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]; 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 &>(),

View File

@ -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);