forked from OctaForge/libostd
inheritance-respecting swap checks
This commit is contained in:
parent
b72e15a8d2
commit
2c09fc968f
|
@ -397,7 +397,7 @@ protected:
|
||||||
char p_buf[32];
|
char p_buf[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for cusotm container formatting */
|
/* for custom container formatting */
|
||||||
|
|
||||||
template<typename T, typename R, typename = EnableIf<
|
template<typename T, typename R, typename = EnableIf<
|
||||||
IsSame<decltype(declval<T>().to_format(declval<R &>(),
|
IsSame<decltype(declval<T>().to_format(declval<R &>(),
|
||||||
|
|
|
@ -49,21 +49,19 @@ template<typename T> AddRvalueReference<T> declval();
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct SwapTest {
|
auto test_swap(int) ->
|
||||||
template<typename U, void (U::*)(U &)> struct Test {};
|
decltype(IsVoid<decltype(declval<T>().swap(declval<T &>()))>());
|
||||||
template<typename U> static char test(Test<U, &U::swap> *);
|
template<typename>
|
||||||
template<typename U> static int test(...);
|
False test_swap(...);
|
||||||
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
||||||
detail::SwapTest<T>::value, bool
|
decltype(test_swap<T>(0))::value, bool
|
||||||
> = true) {
|
> = true) {
|
||||||
a.swap(b);
|
a.swap(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
template<typename T> inline void swap_fb(T &a, T &b, EnableIf<
|
||||||
!detail::SwapTest<T>::value, bool
|
!decltype(test_swap<T>(0))::value, bool
|
||||||
> = true) {
|
> = true) {
|
||||||
T c(move(a));
|
T c(move(a));
|
||||||
a = move(b);
|
a = move(b);
|
||||||
|
|
Loading…
Reference in a new issue