has_trivial_constructor.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED
  8. #define BOOST_TT_HAS_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED
  9. #include <boost/type_traits/intrinsics.hpp>
  10. #include <boost/type_traits/is_pod.hpp>
  11. #include <boost/type_traits/is_default_constructible.hpp>
  12. #ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
  13. #ifdef BOOST_HAS_SGI_TYPE_TRAITS
  14. #include <boost/type_traits/is_same.hpp>
  15. #elif defined(__GNUC__) || defined(__SUNPRO_CC)
  16. #include <boost/type_traits/is_volatile.hpp>
  17. #ifdef BOOST_INTEL
  18. #include <boost/type_traits/is_pod.hpp>
  19. #endif
  20. #endif
  21. #endif
  22. #if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || defined(BOOST_CLANG) || (defined(__SUNPRO_CC) && defined(BOOST_HAS_TRIVIAL_CONSTRUCTOR))
  23. #include <boost/type_traits/is_default_constructible.hpp>
  24. #define BOOST_TT_TRIVIAL_CONSTRUCT_FIX && is_default_constructible<T>::value
  25. #else
  26. //
  27. // Mot all compilers, particularly older GCC versions can handle the fix above.
  28. #define BOOST_TT_TRIVIAL_CONSTRUCT_FIX
  29. #endif
  30. namespace boost {
  31. template <typename T> struct has_trivial_constructor
  32. #ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
  33. : public integral_constant <bool, ((::boost::is_pod<T>::value || BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)) BOOST_TT_TRIVIAL_CONSTRUCT_FIX)>{};
  34. #else
  35. : public integral_constant <bool, ::boost::is_pod<T>::value>{};
  36. #endif
  37. template <> struct has_trivial_constructor<void> : public boost::false_type{};
  38. template <> struct has_trivial_constructor<void const> : public boost::false_type{};
  39. template <> struct has_trivial_constructor<void const volatile> : public boost::false_type{};
  40. template <> struct has_trivial_constructor<void volatile> : public boost::false_type{};
  41. template <class T> struct has_trivial_default_constructor : public has_trivial_constructor<T> {};
  42. #undef BOOST_TT_TRIVIAL_CONSTRUCT_FIX
  43. } // namespace boost
  44. #endif // BOOST_TT_HAS_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED