has_trivial_copy.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_COPY_HPP_INCLUDED
  8. #define BOOST_TT_HAS_TRIVIAL_COPY_HPP_INCLUDED
  9. #include <cstddef> // size_t
  10. #include <boost/type_traits/intrinsics.hpp>
  11. #include <boost/type_traits/is_pod.hpp>
  12. #include <boost/type_traits/is_reference.hpp>
  13. #if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || defined(BOOST_CLANG) || (defined(__SUNPRO_CC) && defined(BOOST_HAS_TRIVIAL_COPY))
  14. #include <boost/type_traits/is_copy_constructible.hpp>
  15. #define BOOST_TT_TRIVIAL_CONSTRUCT_FIX && is_copy_constructible<T>::value
  16. #else
  17. #define BOOST_TT_TRIVIAL_CONSTRUCT_FIX
  18. #endif
  19. #ifdef BOOST_INTEL
  20. #include <boost/type_traits/add_const.hpp>
  21. #include <boost/type_traits/add_lvalue_reference.hpp>
  22. #endif
  23. namespace boost {
  24. template <typename T> struct has_trivial_copy
  25. : public integral_constant<bool,
  26. #ifdef BOOST_HAS_TRIVIAL_COPY
  27. BOOST_HAS_TRIVIAL_COPY(T) BOOST_TT_TRIVIAL_CONSTRUCT_FIX
  28. #else
  29. ::boost::is_pod<T>::value
  30. #endif
  31. >{};
  32. // Arrays are not explicitly copyable:
  33. template <typename T, std::size_t N> struct has_trivial_copy<T[N]> : public false_type{};
  34. template <typename T> struct has_trivial_copy<T[]> : public false_type{};
  35. // Are volatile types ever trivial? We don't really know, so assume not:
  36. template <typename T> struct has_trivial_copy<T volatile> : public false_type{};
  37. template <> struct has_trivial_copy<void> : public false_type{};
  38. #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
  39. template <> struct has_trivial_copy<void const> : public false_type{};
  40. template <> struct has_trivial_copy<void volatile> : public false_type{};
  41. template <> struct has_trivial_copy<void const volatile> : public false_type{};
  42. #endif
  43. template <class T> struct has_trivial_copy<T&> : public false_type{};
  44. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  45. template <class T> struct has_trivial_copy<T&&> : public false_type{};
  46. #endif
  47. template <class T> struct has_trivial_copy_constructor : public has_trivial_copy<T>{};
  48. #undef BOOST_TT_TRIVIAL_CONSTRUCT_FIX
  49. } // namespace boost
  50. #endif // BOOST_TT_HAS_TRIVIAL_COPY_HPP_INCLUDED