sequence.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_HANA_TEST_LAWS_SEQUENCE_HPP
  5. #define BOOST_HANA_TEST_LAWS_SEQUENCE_HPP
  6. #include <boost/hana/assert.hpp>
  7. #include <boost/hana/concept/sequence.hpp>
  8. #include <boost/hana/config.hpp>
  9. #include <boost/hana/core/tag_of.hpp>
  10. #include <boost/hana/functional/capture.hpp>
  11. #include <boost/hana/functional/compose.hpp>
  12. #include <boost/hana/functional/id.hpp>
  13. #include <boost/hana/functional/partial.hpp>
  14. #include <boost/hana/integral_constant.hpp>
  15. #include <boost/hana/optional.hpp>
  16. #include <boost/hana/plus.hpp>
  17. #include <boost/hana/range.hpp>
  18. #include <boost/hana/tuple.hpp>
  19. #include <laws/base.hpp>
  20. #include <support/minimal_product.hpp>
  21. #include <support/seq.hpp>
  22. #include <type_traits>
  23. #include <vector>
  24. namespace boost { namespace hana { namespace test {
  25. template <typename S, typename = when<true>>
  26. struct TestSequence : TestSequence<S, laws> {
  27. using TestSequence<S, laws>::TestSequence;
  28. };
  29. template <typename S>
  30. struct TestSequence<S, laws> {
  31. template <int i>
  32. using eq = integer<i,
  33. Policy::Comparable
  34. | Policy::Constant
  35. >;
  36. template <int i>
  37. using cx_eq = integer<i,
  38. Policy::Comparable
  39. | Policy::Constexpr
  40. >;
  41. template <int i>
  42. using ord = integer<i,
  43. Policy::Orderable
  44. | Policy::Constant
  45. >;
  46. struct undefined { };
  47. TestSequence() {
  48. constexpr auto list = make<S>; (void)list;
  49. constexpr auto foldable = ::seq; (void)foldable;
  50. //////////////////////////////////////////////////////////////////
  51. // Check for Sequence<...>
  52. //////////////////////////////////////////////////////////////////
  53. static_assert(Sequence<decltype(list())>{}, "");
  54. static_assert(Sequence<decltype(list(1))>{}, "");
  55. static_assert(Sequence<decltype(list(1, '2'))>{}, "");
  56. static_assert(Sequence<decltype(list(1, '2', 3.4))>{}, "");
  57. //////////////////////////////////////////////////////////////////
  58. // Check for basic tag consistency
  59. //////////////////////////////////////////////////////////////////
  60. struct Random;
  61. static_assert(std::is_same<tag_of_t<decltype(list())>, S>{}, "");
  62. static_assert(std::is_same<tag_of_t<decltype(list(1))>, S>{}, "");
  63. static_assert(std::is_same<tag_of_t<decltype(list(1, '2'))>, S>{}, "");
  64. static_assert(std::is_same<tag_of_t<decltype(list(1, '2', 3.3))>, S>{}, "");
  65. static_assert(!std::is_same<tag_of_t<Random>, S>{}, "");
  66. //////////////////////////////////////////////////////////////////
  67. // Foldable -> Sequence conversion
  68. //////////////////////////////////////////////////////////////////
  69. {
  70. BOOST_HANA_CONSTANT_CHECK(equal(
  71. to<S>(foldable()),
  72. list()
  73. ));
  74. BOOST_HANA_CONSTANT_CHECK(equal(
  75. to<S>(foldable(eq<0>{})),
  76. list(eq<0>{})
  77. ));
  78. BOOST_HANA_CONSTANT_CHECK(equal(
  79. to<S>(foldable(eq<0>{}, eq<1>{})),
  80. list(eq<0>{}, eq<1>{})
  81. ));
  82. BOOST_HANA_CONSTANT_CHECK(equal(
  83. to<S>(foldable(eq<0>{}, eq<1>{}, eq<2>{})),
  84. list(eq<0>{}, eq<1>{}, eq<2>{})
  85. ));
  86. BOOST_HANA_CONSTANT_CHECK(equal(
  87. to<S>(foldable(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})),
  88. list(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})
  89. ));
  90. }
  91. //////////////////////////////////////////////////////////////////
  92. // make (tautological given our definition of `list`)
  93. //////////////////////////////////////////////////////////////////
  94. BOOST_HANA_CONSTANT_CHECK(equal(
  95. make<S>(),
  96. list()
  97. ));
  98. BOOST_HANA_CONSTANT_CHECK(equal(
  99. make<S>(eq<0>{}),
  100. list(eq<0>{})
  101. ));
  102. BOOST_HANA_CONSTANT_CHECK(equal(
  103. make<S>(eq<0>{}, eq<1>{}),
  104. list(eq<0>{}, eq<1>{})
  105. ));
  106. BOOST_HANA_CONSTANT_CHECK(equal(
  107. make<S>(eq<0>{}, eq<1>{}, eq<2>{}),
  108. list(eq<0>{}, eq<1>{}, eq<2>{})
  109. ));
  110. BOOST_HANA_CONSTANT_CHECK(equal(
  111. make<S>(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}),
  112. list(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{})
  113. ));
  114. }
  115. };
  116. }}} // end namespace boost::hana::test
  117. #endif // !BOOST_HANA_TEST_LAWS_SEQUENCE_HPP