Permalink
Browse files

Add is_swappable and make is_nothrow_swappable honor it

  • Loading branch information...
1 parent ba271a5 commit f7c0092c02b153f73e8dfb806f0a3ec9018a2593 @acmorrow committed Jan 21, 2013
Showing with 28 additions and 5 deletions.
  1. +28 −5 detail/is_nothrow_swappable.hpp
@@ -24,16 +24,39 @@ namespace acm {
namespace adl_swap_ns {
using std::swap;
- template <class T>
- struct is_nothrow_swappable_test {
- static bool constexpr value = noexcept(swap(std::declval<T&>(), std::declval<T&>()));
+ template<typename T>
+ struct is_swappable_test {
+
+ template<typename U>
+ static decltype(swap(std::declval<U&>(), std::declval<U&>())) test(const U&);
+
+ template<typename U>
+ static bool test(...);
+
+ using test_type = decltype(test<T>(std::declval<T&>()));
+ static constexpr bool value = std::is_void<test_type>::value;
+ };
+
+ template<bool, typename T>
+ struct is_nothrow_swappable_test :
+ std::integral_constant<bool, noexcept(swap(std::declval<T&>(), std::declval<T&>()))> {
};
+
+ template<typename T>
+ struct is_nothrow_swappable_test<false, T> :
+ std::false_type {
+ };
+
} // namespace adl_swap_ns
+ template<typename T>
+ struct is_swappable :
+ std::integral_constant<bool, adl_swap_ns::is_swappable_test<T>::value> {};
+
// This really should be part of C++
- template <class T>
+ template<typename T>
struct is_nothrow_swappable
- : std::integral_constant<bool, adl_swap_ns::is_nothrow_swappable_test<T>::value>
+ : std::integral_constant<bool, adl_swap_ns::is_nothrow_swappable_test<is_swappable<T>::value, T>::value>
{};
} // namespace detail

0 comments on commit f7c0092

Please sign in to comment.