make swap respect ADL (while still not requiring it)
This commit is contained in:
parent
82a8ea3902
commit
c34e81be56
|
@ -22,7 +22,7 @@ R partition(R range, U pred) {
|
||||||
R ret = range;
|
R ret = range;
|
||||||
for (; !range.empty(); range.pop_front()) {
|
for (; !range.empty(); range.pop_front()) {
|
||||||
if (pred(range.front())) {
|
if (pred(range.front())) {
|
||||||
octa::swap(range.front(), ret.front());
|
detail::swap_adl(range.front(), ret.front());
|
||||||
ret.pop_front();
|
ret.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ namespace detail {
|
||||||
if (((ch + 1) <= e) && compare(range[sw], range[ch + 1]))
|
if (((ch + 1) <= e) && compare(range[sw], range[ch + 1]))
|
||||||
sw = ch + 1;
|
sw = ch + 1;
|
||||||
if (sw != r) {
|
if (sw != r) {
|
||||||
octa::swap(range[r], range[sw]);
|
detail::swap_adl(range[r], range[sw]);
|
||||||
r = sw;
|
r = sw;
|
||||||
} else return;
|
} else return;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ namespace detail {
|
||||||
}
|
}
|
||||||
RangeSize<R> e = len - 1;
|
RangeSize<R> e = len - 1;
|
||||||
while (e > 0) {
|
while (e > 0) {
|
||||||
octa::swap(range[e], range[0]);
|
detail::swap_adl(range[e], range[0]);
|
||||||
--e;
|
--e;
|
||||||
detail::hs_sift_down(range, 0, e, compare);
|
detail::hs_sift_down(range, 0, e, compare);
|
||||||
}
|
}
|
||||||
|
@ -98,15 +98,15 @@ namespace detail {
|
||||||
detail::heapsort(range, compare);
|
detail::heapsort(range, compare);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
octa::swap(range[range.size() / 2], range.back());
|
detail::swap_adl(range[range.size() / 2], range.back());
|
||||||
RangeSize<R> pi = 0;
|
RangeSize<R> pi = 0;
|
||||||
R pr = range;
|
R pr = range;
|
||||||
pr.pop_back();
|
pr.pop_back();
|
||||||
for (; !pr.empty(); pr.pop_front()) {
|
for (; !pr.empty(); pr.pop_front()) {
|
||||||
if (compare(pr.front(), range.back()))
|
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(0, pi), compare, depth - 1);
|
||||||
detail::introloop(range.slice(pi + 1, range.size()), compare,
|
detail::introloop(range.slice(pi + 1, range.size()), compare,
|
||||||
depth - 1);
|
depth - 1);
|
||||||
|
@ -364,7 +364,7 @@ R2 move(R1 irange, R2 orange) {
|
||||||
template<typename R>
|
template<typename R>
|
||||||
void reverse(R range) {
|
void reverse(R range) {
|
||||||
while (!range.empty()) {
|
while (!range.empty()) {
|
||||||
octa::swap(range.front(), range.back());
|
detail::swap_adl(range.front(), range.back());
|
||||||
range.pop_front();
|
range.pop_front();
|
||||||
range.pop_back();
|
range.pop_back();
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ void generate(R range, F gen) {
|
||||||
template<typename R1, typename R2>
|
template<typename R1, typename R2>
|
||||||
Pair<R1, R2> swap_ranges(R1 range1, R2 range2) {
|
Pair<R1, R2> swap_ranges(R1 range1, R2 range2) {
|
||||||
while (!range1.empty() && !range2.empty()) {
|
while (!range1.empty() && !range2.empty()) {
|
||||||
octa::swap(range1.front(), range2.front());
|
detail::swap_adl(range1.front(), range2.front());
|
||||||
range1.pop_front();
|
range1.pop_front();
|
||||||
range2.pop_front();
|
range2.pop_front();
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,14 +401,14 @@ protected:
|
||||||
|
|
||||||
Hashtable &operator=(Hashtable &&ht) {
|
Hashtable &operator=(Hashtable &&ht) {
|
||||||
clear();
|
clear();
|
||||||
octa::swap(p_size, ht.p_size);
|
swap_adl(p_size, ht.p_size);
|
||||||
octa::swap(p_len, ht.p_len);
|
swap_adl(p_len, ht.p_len);
|
||||||
octa::swap(p_chunks, ht.p_chunks);
|
swap_adl(p_chunks, ht.p_chunks);
|
||||||
octa::swap(p_unused, ht.p_unused);
|
swap_adl(p_unused, ht.p_unused);
|
||||||
octa::swap(p_data.first(), ht.p_data.first());
|
swap_adl(p_data.first(), ht.p_data.first());
|
||||||
octa::swap(p_data.second().second(), ht.p_data.second().second());
|
swap_adl(p_data.second().second(), ht.p_data.second().second());
|
||||||
if (AllocatorPropagateOnContainerMoveAssignment<A>::value)
|
if (AllocatorPropagateOnContainerMoveAssignment<A>::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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,14 +424,14 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(Hashtable &ht) {
|
void swap(Hashtable &ht) {
|
||||||
octa::swap(p_size, ht.p_size);
|
swap_adl(p_size, ht.p_size);
|
||||||
octa::swap(p_len, ht.p_len);
|
swap_adl(p_len, ht.p_len);
|
||||||
octa::swap(p_chunks, ht.p_chunks);
|
swap_adl(p_chunks, ht.p_chunks);
|
||||||
octa::swap(p_unused, ht.p_unused);
|
swap_adl(p_unused, ht.p_unused);
|
||||||
octa::swap(p_data.first(), ht.p_data.first());
|
swap_adl(p_data.first(), ht.p_data.first());
|
||||||
octa::swap(p_data.second().second(), ht.p_data.second().second());
|
swap_adl(p_data.second().second(), ht.p_data.second().second());
|
||||||
if (AllocatorPropagateOnContainerSwap<A>::value)
|
if (AllocatorPropagateOnContainerSwap<A>::value)
|
||||||
octa::swap(p_data.second().first(), ht.p_data.second().first());
|
swap_adl(p_data.second().first(), ht.p_data.second().first());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -32,8 +32,8 @@ namespace detail {
|
||||||
allocator_construct(alloc, &e, forward<U>(key), move(T()));
|
allocator_construct(alloc, &e, forward<U>(key), move(T()));
|
||||||
}
|
}
|
||||||
static inline void swap_elem(Element &a, Element &b) {
|
static inline void swap_elem(Element &a, Element &b) {
|
||||||
octa::swap(*((K *)&a.first), *((K *)&b.first));
|
swap_adl(*((K *)&a.first), *((K *)&b.first));
|
||||||
octa::swap(*((T *)&a.second), *((T *)&b.second));
|
swap_adl(*((T *)&a.second), *((T *)&b.second));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,7 @@ public:
|
||||||
|
|
||||||
void swap(Maybe &v) {
|
void swap(Maybe &v) {
|
||||||
if (this->p_engaged == v.p_engaged) {
|
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 {
|
} else {
|
||||||
if (this->p_engaged) {
|
if (this->p_engaged) {
|
||||||
::new(address_of(v.p_value)) Value(move(this->p_value));
|
::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));
|
::new(address_of(this->p_value)) Value(move(v.p_value));
|
||||||
v.p_value.~Value();
|
v.p_value.~Value();
|
||||||
}
|
}
|
||||||
octa::swap(this->p_engaged, v.p_engaged);
|
detail::swap_adl(this->p_engaged, v.p_engaged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace detail {
|
||||||
}
|
}
|
||||||
template<typename U>
|
template<typename U>
|
||||||
static inline void set_key(T &, const U &, A &) {}
|
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<typename T, typename H, typename C, typename A, bool IsMultihash>
|
template<typename T, typename H, typename C, typename A, bool IsMultihash>
|
||||||
|
|
|
@ -505,7 +505,7 @@ struct ToString<T, EnableIf<detail::IterableTest<T>::value>> {
|
||||||
String operator()(const T &v) const {
|
String operator()(const T &v) const {
|
||||||
String ret("{");
|
String ret("{");
|
||||||
ret += concat(octa::iter(v), ", ", ToString<
|
ret += concat(octa::iter(v), ", ", ToString<
|
||||||
RemoveCv<RemoveReference<
|
RemoveConst<RemoveReference<
|
||||||
RangeReference<decltype(octa::iter(v))>
|
RangeReference<decltype(octa::iter(v))>
|
||||||
>>
|
>>
|
||||||
>());
|
>());
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(TupleLeaf &t) {
|
void swap(TupleLeaf &t) {
|
||||||
octa::swap(get(), t.get());
|
swap_adl(get(), t.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
H &get() { return p_value; }
|
H &get() { return p_value; }
|
||||||
|
@ -168,7 +168,7 @@ namespace detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(TupleLeaf &t) {
|
void swap(TupleLeaf &t) {
|
||||||
octa::swap(get(), t.get());
|
swap_adl(get(), t.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
H &get() { return (H &)*this; }
|
H &get() { return (H &)*this; }
|
||||||
|
|
|
@ -56,13 +56,13 @@ namespace detail {
|
||||||
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> inline void swap(T &a, T &b, EnableIf<
|
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
||||||
detail::SwapTest<T>::value, bool
|
detail::SwapTest<T>::value, bool
|
||||||
> = true) {
|
> = true) {
|
||||||
a.swap(b);
|
a.swap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void swap(T &a, T &b, EnableIf<
|
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
||||||
!detail::SwapTest<T>::value, bool
|
!detail::SwapTest<T>::value, bool
|
||||||
> = true) {
|
> = true) {
|
||||||
T c(move(a));
|
T c(move(a));
|
||||||
|
@ -72,12 +72,19 @@ namespace detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void swap(T &a, T &b) {
|
template<typename T> inline void swap(T &a, T &b) {
|
||||||
detail::swap(a, b);
|
detail::swap_fb(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, Size N> inline void swap(T (&a)[N], T (&b)[N]) {
|
template<typename T, Size N> inline void swap(T (&a)[N], T (&b)[N]) {
|
||||||
for (Size i = 0; i < N; ++i) {
|
for (Size i = 0; i < N; ++i) {
|
||||||
octa::swap(a[i], b[i]);
|
swap(a[i], b[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
template<typename T> inline void swap_adl(T &a, T &b) {
|
||||||
|
using octa::swap;
|
||||||
|
swap(a, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +141,8 @@ struct Pair {
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(Pair &v) {
|
void swap(Pair &v) {
|
||||||
swap(first, v.first);
|
detail::swap_adl(first, v.first);
|
||||||
swap(second, v.second);
|
detail::swap_adl(second, v.second);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -299,8 +306,8 @@ namespace detail {
|
||||||
const U &second() const { return p_second; }
|
const U &second() const { return p_second; }
|
||||||
|
|
||||||
void swap(CompressedPairBase &v) {
|
void swap(CompressedPairBase &v) {
|
||||||
octa::swap(p_first, v.p_first);
|
swap_adl(p_first, v.p_first);
|
||||||
octa::swap(p_second, v.p_second);
|
swap_adl(p_second, v.p_second);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -319,7 +326,7 @@ namespace detail {
|
||||||
const U &second() const { return p_second; }
|
const U &second() const { return p_second; }
|
||||||
|
|
||||||
void swap(CompressedPairBase &v) {
|
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; }
|
const U &second() const { return *this; }
|
||||||
|
|
||||||
void swap(CompressedPairBase &v) {
|
void swap(CompressedPairBase &v) {
|
||||||
octa::swap(p_first, v.p_first);
|
swap_adl(p_first, v.p_first);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -394,11 +394,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(Vector &v) {
|
void swap(Vector &v) {
|
||||||
octa::swap(p_len, v.p_len);
|
detail::swap_adl(p_len, v.p_len);
|
||||||
octa::swap(p_cap, v.p_cap);
|
detail::swap_adl(p_cap, v.p_cap);
|
||||||
octa::swap(p_buf.first(), v.p_buf.first());
|
detail::swap_adl(p_buf.first(), v.p_buf.first());
|
||||||
if (AllocatorPropagateOnContainerSwap<A>::value)
|
if (AllocatorPropagateOnContainerSwap<A>::value)
|
||||||
octa::swap(p_buf.second(), v.p_buf.second());
|
detail::swap_adl(p_buf.second(), v.p_buf.second());
|
||||||
}
|
}
|
||||||
|
|
||||||
A get_allocator() const {
|
A get_allocator() const {
|
||||||
|
|
Loading…
Reference in a new issue