forked from OctaForge/libostd
completely genericized octa::swap (no need for global overloads ever)
parent
42167fdc5a
commit
e9367246b5
|
@ -62,11 +62,6 @@ namespace octa {
|
|||
|
||||
T p_buf[(N > 0) ? N : 1];
|
||||
};
|
||||
|
||||
template<typename T, size_t N>
|
||||
void swap(Array<T, N> &a, Array<T, N> &b) {
|
||||
a.swap(b);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -617,11 +617,6 @@ namespace octa {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void swap(Function<T> &a, Function<T> &b) {
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator==(nullptr_t, const Function<T> &rhs) { return !rhs; }
|
||||
|
||||
|
|
|
@ -36,12 +36,32 @@ namespace octa {
|
|||
|
||||
/* swap */
|
||||
|
||||
template<typename T> void swap(T &a, T &b) {
|
||||
template<typename T>
|
||||
struct __OctaSwapTest {
|
||||
template<typename U, void (U::*)(U &)> struct __OctaTest {};
|
||||
template<typename U> static char __octa_test(__OctaTest<U, &U::swap> *);
|
||||
template<typename U> static int __octa_test(...);
|
||||
static constexpr bool value = (sizeof(__octa_test<T>(0)) == sizeof(char));
|
||||
};
|
||||
|
||||
template<typename T> inline void __octa_swap(T &a, T &b, EnableIf<
|
||||
__OctaSwapTest<T>::value, bool
|
||||
> = true) {
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template<typename T> inline void __octa_swap(T &a, T &b, EnableIf<
|
||||
!__OctaSwapTest<T>::value, bool
|
||||
> = true) {
|
||||
T c(move(a));
|
||||
a = move(b);
|
||||
b = move(c);
|
||||
}
|
||||
|
||||
template<typename T> void swap(T &a, T &b) {
|
||||
__octa_swap(a, b);
|
||||
}
|
||||
|
||||
template<typename T, size_t N> void swap(T (&a)[N], T (&b)[N]) {
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
swap(a[i], b[i]);
|
||||
|
@ -103,11 +123,6 @@ namespace octa {
|
|||
octa::swap(second, v.second);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
void swap(Pair<T, U> &a, Pair<T, U> &b) {
|
||||
a.swap(b);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -311,11 +311,6 @@ namespace octa {
|
|||
octa::swap(p_buf, v.p_buf);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void swap(Vector<T> &a, Vector<T> &b) {
|
||||
a.swap(b);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue