type_traits.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/move for documentation.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #include <boost/move/detail/type_traits.hpp>
  13. #include <boost/move/core.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/core/lightweight_test.hpp>
  16. //
  17. // pod_struct
  18. //
  19. #if defined(BOOST_MOVE_IS_POD)
  20. struct pod_struct
  21. {
  22. int i;
  23. float f;
  24. };
  25. #endif
  26. //
  27. // deleted_copy_and_assign_type
  28. //
  29. #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  30. struct deleted_copy_and_assign_type
  31. {
  32. deleted_copy_and_assign_type(const deleted_copy_and_assign_type&) = delete;
  33. deleted_copy_and_assign_type & operator=(const deleted_copy_and_assign_type&) = delete;
  34. };
  35. #endif //defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  36. //
  37. // boost_move_type
  38. //
  39. class boost_move_type
  40. {
  41. BOOST_MOVABLE_BUT_NOT_COPYABLE(boost_move_type)
  42. public:
  43. boost_move_type(BOOST_RV_REF(boost_move_type)){}
  44. boost_move_type & operator=(BOOST_RV_REF(boost_move_type)){ return *this; }
  45. };
  46. namespace is_pod_test
  47. {
  48. void test()
  49. {
  50. BOOST_STATIC_ASSERT((boost::move_detail::is_pod<int>::value));
  51. #if defined(BOOST_MOVE_IS_POD)
  52. BOOST_STATIC_ASSERT((boost::move_detail::is_pod<pod_struct>::value));
  53. #endif
  54. }
  55. } //namespace is_pod_test
  56. namespace trivially_memcopyable_test {
  57. void test()
  58. {
  59. #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  60. BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<deleted_copy_and_assign_type>::value));
  61. BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<deleted_copy_and_assign_type>::value));
  62. #endif //#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  63. //boost_move_type
  64. BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_constructible<boost_move_type>::value));
  65. BOOST_STATIC_ASSERT(!(boost::move_detail::is_trivially_copy_assignable<boost_move_type>::value));
  66. BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_constructible<boost_move_type>::value));
  67. BOOST_STATIC_ASSERT(!(boost::move_detail::is_copy_assignable<boost_move_type>::value));
  68. //POD
  69. BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_constructible<int>::value));
  70. BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_assignable<int>::value));
  71. BOOST_STATIC_ASSERT((boost::move_detail::is_copy_constructible<int>::value));
  72. BOOST_STATIC_ASSERT((boost::move_detail::is_copy_assignable<int>::value));
  73. #if defined(BOOST_MOVE_IS_POD)
  74. BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_constructible<pod_struct>::value));
  75. BOOST_STATIC_ASSERT((boost::move_detail::is_trivially_copy_assignable<pod_struct>::value));
  76. BOOST_STATIC_ASSERT((boost::move_detail::is_copy_constructible<pod_struct>::value));
  77. BOOST_STATIC_ASSERT((boost::move_detail::is_copy_assignable<pod_struct>::value));
  78. #endif
  79. }
  80. } //namespace trivially_memcopyable_test {
  81. int main()
  82. {
  83. trivially_memcopyable_test::test();
  84. is_pod_test::test();
  85. boost::report_errors();
  86. }