has_nothrow_assign.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. //
  6. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  7. #ifndef BOOST_TT_HAS_NOTHROW_ASSIGN_HPP_INCLUDED
  8. #define BOOST_TT_HAS_NOTHROW_ASSIGN_HPP_INCLUDED
  9. #include <cstddef> // size_t
  10. #include <boost/type_traits/integral_constant.hpp>
  11. #include <boost/type_traits/intrinsics.hpp>
  12. #if !defined(BOOST_HAS_NOTHROW_ASSIGN) || defined(BOOST_MSVC) || defined(BOOST_INTEL)
  13. #include <boost/type_traits/has_trivial_assign.hpp>
  14. #if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  15. #include <boost/type_traits/declval.hpp>
  16. #include <boost/type_traits/is_const.hpp>
  17. #include <boost/type_traits/is_volatile.hpp>
  18. #include <boost/type_traits/is_reference.hpp>
  19. #include <boost/type_traits/is_assignable.hpp>
  20. #include <boost/type_traits/add_reference.hpp>
  21. #include <boost/type_traits/remove_reference.hpp>
  22. #endif
  23. #endif
  24. #if defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__clang__)
  25. #include <boost/type_traits/is_const.hpp>
  26. #include <boost/type_traits/is_volatile.hpp>
  27. #include <boost/type_traits/is_assignable.hpp>
  28. #include <boost/type_traits/is_array.hpp>
  29. #ifdef BOOST_INTEL
  30. #include <boost/type_traits/is_pod.hpp>
  31. #endif
  32. #endif
  33. namespace boost {
  34. #if !defined(BOOST_HAS_NOTHROW_ASSIGN) && !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  35. namespace detail
  36. {
  37. template <class T, bool b1, bool b2> struct has_nothrow_assign_imp{ static const bool value = false; };
  38. template <class T> struct has_nothrow_assign_imp<T, false, true>{ static const bool value = noexcept(boost::declval<typename add_reference<T>::type>() = boost::declval<typename add_reference<T const>::type>()); };
  39. template <class T, std::size_t N> struct has_nothrow_assign_imp<T[N], false, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
  40. template <class T> struct has_nothrow_assign_imp<T[], false, true>{ static const bool value = has_nothrow_assign_imp<T, false, true>::value; };
  41. }
  42. #endif
  43. template <class T>
  44. struct has_nothrow_assign : public integral_constant < bool,
  45. #ifndef BOOST_HAS_NOTHROW_ASSIGN
  46. #if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  47. // Portable C++11 version:
  48. detail::has_nothrow_assign_imp<T,
  49. (is_const<typename remove_reference<T>::type>::value || is_volatile<typename remove_reference<T>::type>::value || is_reference<T>::value),
  50. is_assignable<typename add_reference<T>::type, typename add_reference<const T>::type>::value
  51. >::value
  52. #else
  53. ::boost::has_trivial_assign<T>::value
  54. #endif
  55. #else
  56. BOOST_HAS_NOTHROW_ASSIGN(T)
  57. #endif
  58. > {};
  59. template <class T, std::size_t N> struct has_nothrow_assign <T[N]> : public has_nothrow_assign<T> {};
  60. template <> struct has_nothrow_assign<void> : public false_type{};
  61. template <class T> struct has_nothrow_assign<T volatile> : public false_type{};
  62. template <class T> struct has_nothrow_assign<T&> : public false_type{};
  63. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  64. template <class T> struct has_nothrow_assign<T&&> : public false_type{};
  65. #endif
  66. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  67. template <> struct has_nothrow_assign<void const> : public false_type{};
  68. template <> struct has_nothrow_assign<void const volatile> : public false_type{};
  69. template <> struct has_nothrow_assign<void volatile> : public false_type{};
  70. #endif
  71. } // namespace boost
  72. #endif // BOOST_TT_HAS_NOTHROW_ASSIGN_HPP_INCLUDED