has_nothrow_constructor.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_CONSTRUCTOR_HPP_INCLUDED
  8. #define BOOST_TT_HAS_NOTHROW_CONSTRUCTOR_HPP_INCLUDED
  9. #include <cstddef> // size_t
  10. #include <boost/type_traits/intrinsics.hpp>
  11. #include <boost/type_traits/integral_constant.hpp>
  12. #ifdef BOOST_HAS_NOTHROW_CONSTRUCTOR
  13. #if defined(BOOST_MSVC) || defined(BOOST_INTEL)
  14. #include <boost/type_traits/has_trivial_constructor.hpp>
  15. #endif
  16. #if defined(__GNUC__ ) || defined(__SUNPRO_CC) || defined(__clang__)
  17. #include <boost/type_traits/is_default_constructible.hpp>
  18. #endif
  19. namespace boost {
  20. template <class T> struct has_nothrow_constructor : public integral_constant<bool, BOOST_HAS_NOTHROW_CONSTRUCTOR(T)>{};
  21. #elif !defined(BOOST_NO_CXX11_NOEXCEPT)
  22. #include <boost/type_traits/is_default_constructible.hpp>
  23. #include <boost/type_traits/remove_all_extents.hpp>
  24. #ifdef BOOST_MSVC
  25. #pragma warning(push)
  26. #pragma warning(disable:4197) // top-level volatile in cast is ignored
  27. #endif
  28. namespace boost { namespace detail{
  29. template <class T, bool b> struct has_nothrow_constructor_imp : public boost::integral_constant<bool, false>{};
  30. template <class T> struct has_nothrow_constructor_imp<T, true> : public boost::integral_constant<bool, noexcept(T())>{};
  31. template <class T, std::size_t N> struct has_nothrow_constructor_imp<T[N], true> : public has_nothrow_constructor_imp<T, true> {};
  32. }
  33. template <class T> struct has_nothrow_constructor : public detail::has_nothrow_constructor_imp<T, is_default_constructible<T>::value>{};
  34. #ifdef BOOST_MSVC
  35. #pragma warning(pop)
  36. #endif
  37. #else
  38. #include <boost/type_traits/has_trivial_constructor.hpp>
  39. namespace boost {
  40. template <class T> struct has_nothrow_constructor : public ::boost::has_trivial_constructor<T> {};
  41. #endif
  42. template<> struct has_nothrow_constructor<void> : public false_type {};
  43. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  44. template<> struct has_nothrow_constructor<void const> : public false_type{};
  45. template<> struct has_nothrow_constructor<void const volatile> : public false_type{};
  46. template<> struct has_nothrow_constructor<void volatile> : public false_type{};
  47. #endif
  48. template <class T> struct has_nothrow_default_constructor : public has_nothrow_constructor<T>{};
  49. } // namespace boost
  50. #endif // BOOST_TT_HAS_NOTHROW_CONSTRUCTOR_HPP_INCLUDED