define_struct_empty.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*=============================================================================
  2. Copyright (c) 2016 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/detail/lightweight_test.hpp>
  7. #include <boost/fusion/container.hpp>
  8. #include <boost/fusion/sequence.hpp>
  9. #include <boost/fusion/sequence/io/out.hpp>
  10. #include <boost/fusion/iterator/equal_to.hpp>
  11. #include <boost/fusion/adapted/struct/define_struct.hpp>
  12. #include <boost/mpl/assert.hpp>
  13. #include <boost/mpl/is_sequence.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <iostream>
  16. BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), empty_struct, )
  17. int
  18. main()
  19. {
  20. using namespace boost;
  21. using namespace boost::fusion;
  22. std::cout << tuple_open('[');
  23. std::cout << tuple_close(']');
  24. std::cout << tuple_delimiter(", ");
  25. {
  26. BOOST_MPL_ASSERT_NOT((traits::is_view<empty_struct>));
  27. BOOST_STATIC_ASSERT(!traits::is_view<empty_struct>::value);
  28. empty_struct e;
  29. std::cout << e << std::endl;
  30. BOOST_TEST(e == make_vector());
  31. BOOST_STATIC_ASSERT(fusion::result_of::size<empty_struct>::value == 0);
  32. BOOST_STATIC_ASSERT(fusion::result_of::empty<empty_struct>::value);
  33. }
  34. {
  35. vector<> v;
  36. empty_struct e;
  37. BOOST_TEST(v == e);
  38. BOOST_TEST_NOT(v != e);
  39. BOOST_TEST_NOT(v < e);
  40. BOOST_TEST(v <= e);
  41. BOOST_TEST_NOT(v > e);
  42. BOOST_TEST(v >= e);
  43. }
  44. {
  45. empty_struct e;
  46. // conversion from empty_struct to vector
  47. vector<> v(e);
  48. v = e;
  49. // conversion from empty_struct to list
  50. //list<> l(e);
  51. //l = e;
  52. }
  53. { // begin/end
  54. typedef fusion::result_of::begin<empty_struct>::type b;
  55. typedef fusion::result_of::end<empty_struct>::type e;
  56. BOOST_MPL_ASSERT((fusion::result_of::equal_to<b, e>));
  57. }
  58. BOOST_MPL_ASSERT((mpl::is_sequence<empty_struct>));
  59. return boost::report_errors();
  60. }