is_nothrow_move_constructible.hpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
  2. // (C) Copyright Eric Friedman 2002-2003.
  3. // (C) Copyright Antony Polukhin 2013.
  4. // Use, modification and distribution are subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt).
  7. //
  8. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  9. #ifndef BOOST_TT_IS_NOTHROW_MOVE_CONSTRUCTIBLE_HPP_INCLUDED
  10. #define BOOST_TT_IS_NOTHROW_MOVE_CONSTRUCTIBLE_HPP_INCLUDED
  11. #include <cstddef> // size_t
  12. #include <boost/config.hpp>
  13. #include <boost/type_traits/intrinsics.hpp>
  14. #include <boost/type_traits/integral_constant.hpp>
  15. #include <boost/detail/workaround.hpp>
  16. #include <boost/type_traits/is_complete.hpp>
  17. #include <boost/static_assert.hpp>
  18. #ifdef BOOST_IS_NOTHROW_MOVE_CONSTRUCT
  19. namespace boost {
  20. template <class T>
  21. struct is_nothrow_move_constructible : public integral_constant<bool, BOOST_IS_NOTHROW_MOVE_CONSTRUCT(T)>
  22. {
  23. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_nothrow_move_constructible must be complete types");
  24. };
  25. template <class T> struct is_nothrow_move_constructible<volatile T> : public ::boost::false_type {};
  26. template <class T> struct is_nothrow_move_constructible<const volatile T> : public ::boost::false_type{};
  27. #elif !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
  28. #include <boost/type_traits/declval.hpp>
  29. #include <boost/type_traits/enable_if.hpp>
  30. namespace boost{ namespace detail{
  31. template <class T, class Enable = void>
  32. struct false_or_cpp11_noexcept_move_constructible: public ::boost::false_type {};
  33. template <class T>
  34. struct false_or_cpp11_noexcept_move_constructible <
  35. T,
  36. typename ::boost::enable_if_<sizeof(T) && BOOST_NOEXCEPT_EXPR(T(::boost::declval<T>()))>::type
  37. > : public ::boost::integral_constant<bool, BOOST_NOEXCEPT_EXPR(T(::boost::declval<T>()))>
  38. {};
  39. }
  40. template <class T> struct is_nothrow_move_constructible
  41. : public integral_constant<bool, ::boost::detail::false_or_cpp11_noexcept_move_constructible<T>::value>
  42. {
  43. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_nothrow_move_constructible must be complete types");
  44. };
  45. template <class T> struct is_nothrow_move_constructible<volatile T> : public ::boost::false_type {};
  46. template <class T> struct is_nothrow_move_constructible<const volatile T> : public ::boost::false_type{};
  47. template <class T, std::size_t N> struct is_nothrow_move_constructible<T[N]> : public ::boost::false_type{};
  48. template <class T> struct is_nothrow_move_constructible<T[]> : public ::boost::false_type{};
  49. #else
  50. #include <boost/type_traits/has_trivial_move_constructor.hpp>
  51. #include <boost/type_traits/has_nothrow_copy.hpp>
  52. #include <boost/type_traits/is_array.hpp>
  53. namespace boost{
  54. template <class T>
  55. struct is_nothrow_move_constructible
  56. : public integral_constant<bool,
  57. (::boost::has_trivial_move_constructor<T>::value || ::boost::has_nothrow_copy<T>::value) && !::boost::is_array<T>::value>
  58. {
  59. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_nothrow_move_constructible must be complete types");
  60. };
  61. #endif
  62. template <> struct is_nothrow_move_constructible<void> : false_type{};
  63. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  64. template <> struct is_nothrow_move_constructible<void const> : false_type{};
  65. template <> struct is_nothrow_move_constructible<void volatile> : false_type{};
  66. template <> struct is_nothrow_move_constructible<void const volatile> : false_type{};
  67. #endif
  68. // References are always trivially constructible, even if the thing they reference is not:
  69. template <class T> struct is_nothrow_move_constructible<T&> : public ::boost::true_type{};
  70. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  71. template <class T> struct is_nothrow_move_constructible<T&&> : public ::boost::true_type{};
  72. #endif
  73. } // namespace boost
  74. #endif // BOOST_TT_IS_NOTHROW_MOVE_CONSTRUCTIBLE_HPP_INCLUDED