unused.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*=============================================================================
  2. Copyright (c) 2018 Kohei Takahashi
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <boost/config.hpp>
  7. #include <boost/fusion/support/unused.hpp>
  8. #include <boost/type_traits/detail/yes_no_type.hpp>
  9. #include <boost/static_assert.hpp>
  10. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  11. #include <utility>
  12. #endif
  13. struct T { };
  14. void unused_construction()
  15. {
  16. boost::fusion::unused_type dephault;
  17. boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED parenthesis = boost::fusion::unused_type();
  18. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  19. boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED brace{};
  20. boost::fusion::unused_type BOOST_ATTRIBUTE_UNUSED list_copy = {};
  21. #endif
  22. boost::fusion::unused_type copy_copy BOOST_ATTRIBUTE_UNUSED = dephault;
  23. boost::fusion::unused_type copy_direct BOOST_ATTRIBUTE_UNUSED (dephault);
  24. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  25. boost::fusion::unused_type copy_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {dephault};
  26. boost::fusion::unused_type copy_direct_brace BOOST_ATTRIBUTE_UNUSED {dephault};
  27. #endif
  28. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  29. boost::fusion::unused_type move_copy BOOST_ATTRIBUTE_UNUSED = std::move(dephault);
  30. boost::fusion::unused_type move_direct BOOST_ATTRIBUTE_UNUSED (std::move(dephault));
  31. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  32. boost::fusion::unused_type move_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {std::move(dephault)};
  33. boost::fusion::unused_type move_direct_brace BOOST_ATTRIBUTE_UNUSED {std::move(dephault)};
  34. #endif
  35. #endif
  36. T value;
  37. boost::fusion::unused_type T_copy_copy BOOST_ATTRIBUTE_UNUSED = value;
  38. boost::fusion::unused_type T_copy_direct BOOST_ATTRIBUTE_UNUSED (value);
  39. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  40. boost::fusion::unused_type T_copy_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {value};
  41. boost::fusion::unused_type T_copy_direct_brace BOOST_ATTRIBUTE_UNUSED {value};
  42. #endif
  43. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  44. boost::fusion::unused_type T_move_copy BOOST_ATTRIBUTE_UNUSED = std::move(value);
  45. boost::fusion::unused_type T_move_direct BOOST_ATTRIBUTE_UNUSED (std::move(value));
  46. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  47. boost::fusion::unused_type T_move_copy_brace_direct BOOST_ATTRIBUTE_UNUSED = {std::move(value)};
  48. boost::fusion::unused_type T_move_direct_brace BOOST_ATTRIBUTE_UNUSED {std::move(value)};
  49. #endif
  50. #endif
  51. }
  52. void unused_assignment()
  53. {
  54. boost::fusion::unused_type val1, val2;
  55. val1 = val2;
  56. #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
  57. val1 = {};
  58. #endif
  59. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  60. val1 = std::move(val2);
  61. #endif
  62. T value;
  63. val1 = value;
  64. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  65. val1 = std::move(value);
  66. #endif
  67. }
  68. boost::type_traits::yes_type test_unused(boost::fusion::detail::unused_only const&);
  69. boost::type_traits::no_type test_unused(...);
  70. void only_unused()
  71. {
  72. BOOST_STATIC_ASSERT((sizeof(test_unused(boost::fusion::unused)) == sizeof(boost::type_traits::yes_type)));
  73. BOOST_STATIC_ASSERT((sizeof(test_unused(0)) == sizeof(boost::type_traits::no_type)));
  74. boost::fusion::unused_type my_unused;
  75. (void)my_unused;
  76. BOOST_STATIC_ASSERT((sizeof(test_unused(my_unused)) == sizeof(boost::type_traits::yes_type)));
  77. }