diff --git a/octa/algorithm.hh b/octa/algorithm.hh index 57c018f..f2d8e37 100644 --- a/octa/algorithm.hh +++ b/octa/algorithm.hh @@ -22,7 +22,7 @@ R partition(R range, U pred) { R ret = range; for (; !range.empty(); range.pop_front()) { if (pred(range.front())) { - octa::swap(range.front(), ret.front()); + detail::swap_adl(range.front(), ret.front()); ret.pop_front(); } } @@ -66,7 +66,7 @@ namespace detail { if (((ch + 1) <= e) && compare(range[sw], range[ch + 1])) sw = ch + 1; if (sw != r) { - octa::swap(range[r], range[sw]); + detail::swap_adl(range[r], range[sw]); r = sw; } else return; } @@ -82,7 +82,7 @@ namespace detail { } RangeSize e = len - 1; while (e > 0) { - octa::swap(range[e], range[0]); + detail::swap_adl(range[e], range[0]); --e; detail::hs_sift_down(range, 0, e, compare); } @@ -98,15 +98,15 @@ namespace detail { detail::heapsort(range, compare); return; } - octa::swap(range[range.size() / 2], range.back()); + detail::swap_adl(range[range.size() / 2], range.back()); RangeSize pi = 0; R pr = range; pr.pop_back(); for (; !pr.empty(); pr.pop_front()) { if (compare(pr.front(), range.back())) - octa::swap(pr.front(), range[pi++]); + detail::swap_adl(pr.front(), range[pi++]); } - octa::swap(range[pi], range.back()); + detail::swap_adl(range[pi], range.back()); detail::introloop(range.slice(0, pi), compare, depth - 1); detail::introloop(range.slice(pi + 1, range.size()), compare, depth - 1); @@ -364,7 +364,7 @@ R2 move(R1 irange, R2 orange) { template void reverse(R range) { while (!range.empty()) { - octa::swap(range.front(), range.back()); + detail::swap_adl(range.front(), range.back()); range.pop_front(); range.pop_back(); } @@ -392,7 +392,7 @@ void generate(R range, F gen) { template Pair swap_ranges(R1 range1, R2 range2) { while (!range1.empty() && !range2.empty()) { - octa::swap(range1.front(), range2.front()); + detail::swap_adl(range1.front(), range2.front()); range1.pop_front(); range2.pop_front(); } diff --git a/octa/internal/hashtable.hh b/octa/internal/hashtable.hh index 6f4e03d..e14e816 100644 --- a/octa/internal/hashtable.hh +++ b/octa/internal/hashtable.hh @@ -401,14 +401,14 @@ protected: Hashtable &operator=(Hashtable &&ht) { clear(); - octa::swap(p_size, ht.p_size); - octa::swap(p_len, ht.p_len); - octa::swap(p_chunks, ht.p_chunks); - octa::swap(p_unused, ht.p_unused); - octa::swap(p_data.first(), ht.p_data.first()); - octa::swap(p_data.second().second(), ht.p_data.second().second()); + swap_adl(p_size, ht.p_size); + swap_adl(p_len, ht.p_len); + swap_adl(p_chunks, ht.p_chunks); + swap_adl(p_unused, ht.p_unused); + swap_adl(p_data.first(), ht.p_data.first()); + swap_adl(p_data.second().second(), ht.p_data.second().second()); if (AllocatorPropagateOnContainerMoveAssignment::value) - octa::swap(p_data.second().first(), ht.p_data.second().first()); + swap_adl(p_data.second().first(), ht.p_data.second().first()); return *this; } @@ -424,14 +424,14 @@ protected: } void swap(Hashtable &ht) { - octa::swap(p_size, ht.p_size); - octa::swap(p_len, ht.p_len); - octa::swap(p_chunks, ht.p_chunks); - octa::swap(p_unused, ht.p_unused); - octa::swap(p_data.first(), ht.p_data.first()); - octa::swap(p_data.second().second(), ht.p_data.second().second()); + swap_adl(p_size, ht.p_size); + swap_adl(p_len, ht.p_len); + swap_adl(p_chunks, ht.p_chunks); + swap_adl(p_unused, ht.p_unused); + swap_adl(p_data.first(), ht.p_data.first()); + swap_adl(p_data.second().second(), ht.p_data.second().second()); if (AllocatorPropagateOnContainerSwap::value) - octa::swap(p_data.second().first(), ht.p_data.second().first()); + swap_adl(p_data.second().first(), ht.p_data.second().first()); } public: diff --git a/octa/map.hh b/octa/map.hh index 3da9fdc..67b15e9 100644 --- a/octa/map.hh +++ b/octa/map.hh @@ -32,8 +32,8 @@ namespace detail { allocator_construct(alloc, &e, forward(key), move(T())); } static inline void swap_elem(Element &a, Element &b) { - octa::swap(*((K *)&a.first), *((K *)&b.first)); - octa::swap(*((T *)&a.second), *((T *)&b.second)); + swap_adl(*((K *)&a.first), *((K *)&b.first)); + swap_adl(*((T *)&a.second), *((T *)&b.second)); } }; diff --git a/octa/maybe.hh b/octa/maybe.hh index f7625ac..e753355 100644 --- a/octa/maybe.hh +++ b/octa/maybe.hh @@ -240,7 +240,7 @@ public: void swap(Maybe &v) { if (this->p_engaged == v.p_engaged) { - if (this->p_engaged) octa::swap(this->p_value, v.p_value); + if (this->p_engaged) detail::swap_adl(this->p_value, v.p_value); } else { if (this->p_engaged) { ::new(address_of(v.p_value)) Value(move(this->p_value)); @@ -249,7 +249,7 @@ public: ::new(address_of(this->p_value)) Value(move(v.p_value)); v.p_value.~Value(); } - octa::swap(this->p_engaged, v.p_engaged); + detail::swap_adl(this->p_engaged, v.p_engaged); } } diff --git a/octa/set.hh b/octa/set.hh index 32e9639..28c8f55 100644 --- a/octa/set.hh +++ b/octa/set.hh @@ -26,7 +26,7 @@ namespace detail { } template static inline void set_key(T &, const U &, A &) {} - static inline void swap_elem(T &a, T &b) { octa::swap(a, b); } + static inline void swap_elem(T &a, T &b) { swap_adl(a, b); } }; template diff --git a/octa/string.hh b/octa/string.hh index f278a9d..2aa849c 100644 --- a/octa/string.hh +++ b/octa/string.hh @@ -505,7 +505,7 @@ struct ToString::value>> { String operator()(const T &v) const { String ret("{"); ret += concat(octa::iter(v), ", ", ToString< - RemoveCv >> >()); diff --git a/octa/tuple.hh b/octa/tuple.hh index b4e72a9..3bb31ba 100644 --- a/octa/tuple.hh +++ b/octa/tuple.hh @@ -114,7 +114,7 @@ namespace detail { } void swap(TupleLeaf &t) { - octa::swap(get(), t.get()); + swap_adl(get(), t.get()); } H &get() { return p_value; } @@ -168,7 +168,7 @@ namespace detail { } void swap(TupleLeaf &t) { - octa::swap(get(), t.get()); + swap_adl(get(), t.get()); } H &get() { return (H &)*this; } diff --git a/octa/utility.hh b/octa/utility.hh index bc703f2..7ded16d 100644 --- a/octa/utility.hh +++ b/octa/utility.hh @@ -56,13 +56,13 @@ namespace detail { static constexpr bool value = (sizeof(test(0)) == sizeof(char)); }; - template inline void swap(T &a, T &b, EnableIf< + template inline void swap_fb(T &a, T &b, EnableIf< detail::SwapTest::value, bool > = true) { a.swap(b); } - template inline void swap(T &a, T &b, EnableIf< + template inline void swap_fb(T &a, T &b, EnableIf< !detail::SwapTest::value, bool > = true) { T c(move(a)); @@ -72,12 +72,19 @@ namespace detail { } template inline void swap(T &a, T &b) { - detail::swap(a, b); + detail::swap_fb(a, b); } template inline void swap(T (&a)[N], T (&b)[N]) { for (Size i = 0; i < N; ++i) { - octa::swap(a[i], b[i]); + swap(a[i], b[i]); + } +} + +namespace detail { + template inline void swap_adl(T &a, T &b) { + using octa::swap; + swap(a, b); } } @@ -134,8 +141,8 @@ struct Pair { } void swap(Pair &v) { - swap(first, v.first); - swap(second, v.second); + detail::swap_adl(first, v.first); + detail::swap_adl(second, v.second); } }; @@ -299,8 +306,8 @@ namespace detail { const U &second() const { return p_second; } void swap(CompressedPairBase &v) { - octa::swap(p_first, v.p_first); - octa::swap(p_second, v.p_second); + swap_adl(p_first, v.p_first); + swap_adl(p_second, v.p_second); } }; @@ -319,7 +326,7 @@ namespace detail { const U &second() const { return p_second; } void swap(CompressedPairBase &v) { - octa::swap(p_second, v.p_second); + swap_adl(p_second, v.p_second); } }; @@ -338,7 +345,7 @@ namespace detail { const U &second() const { return *this; } void swap(CompressedPairBase &v) { - octa::swap(p_first, v.p_first); + swap_adl(p_first, v.p_first); } }; diff --git a/octa/vector.hh b/octa/vector.hh index ac5dcb4..b7620b9 100644 --- a/octa/vector.hh +++ b/octa/vector.hh @@ -394,11 +394,11 @@ public: } void swap(Vector &v) { - octa::swap(p_len, v.p_len); - octa::swap(p_cap, v.p_cap); - octa::swap(p_buf.first(), v.p_buf.first()); + detail::swap_adl(p_len, v.p_len); + detail::swap_adl(p_cap, v.p_cap); + detail::swap_adl(p_buf.first(), v.p_buf.first()); if (AllocatorPropagateOnContainerSwap::value) - octa::swap(p_buf.second(), v.p_buf.second()); + detail::swap_adl(p_buf.second(), v.p_buf.second()); } A get_allocator() const {