is_default_constructible.hpp 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // (C) Copyright John Maddock 2015.
  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_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED
  8. #define BOOST_TT_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED
  9. #include <cstddef> // size_t
  10. #include <boost/type_traits/integral_constant.hpp>
  11. #include <boost/detail/workaround.hpp>
  12. #include <boost/type_traits/is_complete.hpp>
  13. #include <boost/static_assert.hpp>
  14. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
  15. #include <boost/type_traits/is_abstract.hpp>
  16. #endif
  17. #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ <= 5)) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1800))
  18. #include <utility> // std::pair
  19. #endif
  20. #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500)
  21. #include <boost/type_traits/detail/yes_no_type.hpp>
  22. namespace boost{
  23. namespace detail{
  24. struct is_default_constructible_imp
  25. {
  26. template<typename _Tp, typename = decltype(_Tp())>
  27. static boost::type_traits::yes_type test(int);
  28. template<typename>
  29. static boost::type_traits::no_type test(...);
  30. };
  31. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
  32. template<class T, bool b>
  33. struct is_default_constructible_abstract_filter
  34. {
  35. static const bool value = sizeof(is_default_constructible_imp::test<T>(0)) == sizeof(boost::type_traits::yes_type);
  36. };
  37. template<class T>
  38. struct is_default_constructible_abstract_filter<T, true>
  39. {
  40. static const bool value = false;
  41. };
  42. #endif
  43. }
  44. #if BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40700)
  45. template <class T> struct is_default_constructible : public integral_constant<bool, detail::is_default_constructible_abstract_filter<T, boost::is_abstract<T>::value>::value>
  46. {
  47. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_default_constructible must be complete types");
  48. };
  49. #else
  50. template <class T> struct is_default_constructible : public integral_constant<bool, sizeof(boost::detail::is_default_constructible_imp::test<T>(0)) == sizeof(boost::type_traits::yes_type)>
  51. {
  52. BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_default_constructible must be complete types");
  53. };
  54. #endif
  55. template <class T, std::size_t N> struct is_default_constructible<T[N]> : public is_default_constructible<T>{};
  56. template <class T> struct is_default_constructible<T[]> : public is_default_constructible<T>{};
  57. template <class T> struct is_default_constructible<T&> : public integral_constant<bool, false>{};
  58. #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ <= 5))|| (defined(BOOST_MSVC) && (BOOST_MSVC == 1800))
  59. template <class T, class U> struct is_default_constructible<std::pair<T,U> > : public integral_constant<bool, is_default_constructible<T>::value && is_default_constructible<U>::value>{};
  60. #endif
  61. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  62. template <class T> struct is_default_constructible<T&&> : public integral_constant<bool, false>{};
  63. #endif
  64. template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
  65. template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
  66. template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};
  67. template <> struct is_default_constructible<void const volatile> : public integral_constant<bool, false>{};
  68. #else
  69. #include <boost/type_traits/is_pod.hpp>
  70. namespace boost{
  71. // We don't know how to implement this, note we can not use has_trivial_constructor here
  72. // because the correct implementation of that trait requires this one:
  73. template <class T> struct is_default_constructible : public is_pod<T>{};
  74. template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
  75. template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
  76. template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};
  77. template <> struct is_default_constructible<void const volatile> : public integral_constant<bool, false>{};
  78. #endif
  79. } // namespace boost
  80. #endif // BOOST_TT_IS_DEFAULT_CONSTRUCTIBLE_HPP_INCLUDED