is_nothrow_swappable.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED
  2. #define BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED
  3. // Copyright 2017 Peter Dimov
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt
  8. #include <boost/config.hpp>
  9. #include <boost/config/workaround.hpp>
  10. #if defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_NO_CXX11_NOEXCEPT) || defined(BOOST_NO_CXX11_DECLTYPE) \
  11. || defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) || BOOST_WORKAROUND(BOOST_GCC, < 40700)
  12. #include <boost/type_traits/is_scalar.hpp>
  13. #include <boost/type_traits/is_const.hpp>
  14. #include <boost/type_traits/integral_constant.hpp>
  15. namespace boost
  16. {
  17. template <class T> struct is_nothrow_swappable : boost::integral_constant<bool,
  18. boost::is_scalar<T>::value && !boost::is_const<T>::value> {};
  19. template <class T, class U> struct is_nothrow_swappable_with : false_type {};
  20. template <class T> struct is_nothrow_swappable_with<T, T> : is_nothrow_swappable<T> {};
  21. }
  22. #else
  23. #include <boost/type_traits/declval.hpp>
  24. #include <boost/type_traits/integral_constant.hpp>
  25. #include <algorithm>
  26. namespace boost
  27. {
  28. namespace type_traits_swappable_detail
  29. {
  30. using std::swap;
  31. template<class T, class U, bool B = noexcept(swap(declval<T>(), declval<U>()))> integral_constant<bool, B> is_nothrow_swappable_with_impl( int );
  32. template<class T, class U> false_type is_nothrow_swappable_with_impl( ... );
  33. template<class T, class U>
  34. struct is_nothrow_swappable_with_helper { typedef decltype( type_traits_swappable_detail::is_nothrow_swappable_with_impl<T, U>(0) ) type; };
  35. template<class T, bool B = noexcept(swap(declval<T&>(), declval<T&>()))> integral_constant<bool, B> is_nothrow_swappable_impl( int );
  36. template<class T> false_type is_nothrow_swappable_impl( ... );
  37. template<class T>
  38. struct is_nothrow_swappable_helper { typedef decltype( type_traits_swappable_detail::is_nothrow_swappable_impl<T>(0) ) type; };
  39. } // namespace type_traits_swappable_detail
  40. template<class T, class U> struct is_nothrow_swappable_with: type_traits_swappable_detail::is_nothrow_swappable_with_helper<T, U>::type
  41. {
  42. };
  43. template<class T> struct is_nothrow_swappable: type_traits_swappable_detail::is_nothrow_swappable_helper<T>::type
  44. {
  45. };
  46. } // namespace boost
  47. #endif
  48. #endif // #ifndef BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED