sp_nothrow_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // sp_nothrow_test.cpp
  3. //
  4. // Copyright 2016 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/config.hpp>
  11. #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )
  12. int main()
  13. {
  14. }
  15. #else
  16. #include <boost/shared_ptr.hpp>
  17. #include <boost/shared_array.hpp>
  18. #include <boost/weak_ptr.hpp>
  19. #include <boost/enable_shared_from_this.hpp>
  20. #include <boost/scoped_ptr.hpp>
  21. #include <boost/scoped_array.hpp>
  22. #include <boost/intrusive_ptr.hpp>
  23. #include <boost/core/lightweight_test_trait.hpp>
  24. #include <type_traits>
  25. template<class T> void test_copy()
  26. {
  27. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_constructible<T> ));
  28. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_assignable<T> ));
  29. }
  30. template<class T> void test_move()
  31. {
  32. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<T> ));
  33. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<T> ));
  34. }
  35. template<class T> void test_default()
  36. {
  37. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_default_constructible<T> ));
  38. }
  39. template<class T> void test_destroy()
  40. {
  41. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_destructible<T> ));
  42. }
  43. template<class T> void test_cmd()
  44. {
  45. test_copy<T>();
  46. test_move<T>();
  47. test_default<T>();
  48. }
  49. struct X
  50. {
  51. };
  52. struct Y: public boost::enable_shared_from_this<Y>
  53. {
  54. };
  55. int main()
  56. {
  57. test_cmd< boost::shared_ptr<X> >();
  58. test_cmd< boost::shared_array<X> >();
  59. test_cmd< boost::weak_ptr<X> >();
  60. test_copy< Y >();
  61. test_default< Y >();
  62. test_destroy< Y >();
  63. // test_move< Y >();
  64. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<Y> ));
  65. #if !( defined( BOOST_MSVC ) && BOOST_MSVC == 1700 )
  66. BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<Y> ));
  67. #endif
  68. test_default< boost::scoped_ptr<X> >();
  69. test_default< boost::scoped_array<X> >();
  70. test_move< boost::intrusive_ptr<X> >();
  71. test_default< boost::intrusive_ptr<X> >();
  72. return boost::report_errors();
  73. }
  74. #endif // #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )