inheritance-respecting swap checks

master
Daniel Kolesa 2015-07-11 19:44:58 +01:00
parent b72e15a8d2
commit 2c09fc968f
2 changed files with 7 additions and 9 deletions

View File

@ -397,7 +397,7 @@ protected:
char p_buf[32];
};
/* for cusotm container formatting */
/* for custom container formatting */
template<typename T, typename R, typename = EnableIf<
IsSame<decltype(declval<T>().to_format(declval<R &>(),

View File

@ -49,21 +49,19 @@ template<typename T> AddRvalueReference<T> declval();
namespace detail {
template<typename T>
struct SwapTest {
template<typename U, void (U::*)(U &)> struct Test {};
template<typename U> static char test(Test<U, &U::swap> *);
template<typename U> static int test(...);
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
};
auto test_swap(int) ->
decltype(IsVoid<decltype(declval<T>().swap(declval<T &>()))>());
template<typename>
False test_swap(...);
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) {
a.swap(b);
}
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) {
T c(move(a));
a = move(b);