seq.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include <boost/hana/bool.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/functional/always.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. #include <laws/applicative.hpp>
  9. #include <laws/base.hpp>
  10. #include <laws/comparable.hpp>
  11. #include <laws/foldable.hpp>
  12. #include <laws/functor.hpp>
  13. #include <laws/iterable.hpp>
  14. #include <laws/monad.hpp>
  15. #include <laws/monad_plus.hpp>
  16. #include <laws/orderable.hpp>
  17. #include <laws/searchable.hpp>
  18. #include <laws/sequence.hpp>
  19. #include <support/seq.hpp>
  20. namespace hana = boost::hana;
  21. using hana::test::ct_eq;
  22. using hana::test::ct_ord;
  23. int main() {
  24. auto eqs = hana::make_tuple(
  25. ::seq()
  26. , ::seq(ct_eq<0>{})
  27. , ::seq(ct_eq<0>{}, ct_eq<1>{})
  28. , ::seq(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  29. , ::seq(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})
  30. );
  31. (void)eqs;
  32. auto nested_eqs = hana::make_tuple(
  33. ::seq()
  34. , ::seq(
  35. ::seq(ct_eq<0>{}))
  36. , ::seq(
  37. ::seq(ct_eq<0>{}),
  38. ::seq(ct_eq<1>{}, ct_eq<2>{}))
  39. , ::seq(
  40. ::seq(ct_eq<0>{}),
  41. ::seq(ct_eq<1>{}, ct_eq<2>{}),
  42. ::seq(ct_eq<3>{}, ct_eq<4>{}))
  43. );
  44. (void)nested_eqs;
  45. auto eq_keys = hana::make_tuple(ct_eq<0>{}, ct_eq<3>{}, ct_eq<10>{});
  46. (void)eq_keys;
  47. auto predicates = hana::make_tuple(
  48. hana::equal.to(ct_eq<0>{}), hana::equal.to(ct_eq<3>{}), hana::equal.to(ct_eq<10>{}),
  49. hana::always(hana::true_c), hana::always(hana::false_c)
  50. );
  51. (void)predicates;
  52. auto ords = hana::make_tuple(
  53. ::seq()
  54. , ::seq(ct_ord<0>{})
  55. , ::seq(ct_ord<0>{}, ct_ord<1>{})
  56. , ::seq(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{})
  57. , ::seq(ct_ord<0>{}, ct_ord<1>{}, ct_ord<2>{}, ct_ord<3>{})
  58. );
  59. (void)ords;
  60. //////////////////////////////////////////////////////////////////////////
  61. // Comparable, Orderable
  62. //////////////////////////////////////////////////////////////////////////
  63. #ifdef BOOST_HANA_TEST_ORDERABLE
  64. hana::test::TestComparable<::Seq>{eqs};
  65. hana::test::TestOrderable<::Seq>{ords};
  66. #endif
  67. #ifdef BOOST_HANA_TEST_ITERABLE
  68. //////////////////////////////////////////////////////////////////////////
  69. // Foldable
  70. //////////////////////////////////////////////////////////////////////////
  71. hana::test::TestFoldable<::Seq>{eqs};
  72. //////////////////////////////////////////////////////////////////////////
  73. // Iterable
  74. //////////////////////////////////////////////////////////////////////////
  75. {
  76. hana::test::TestIterable<::Seq>{eqs};
  77. }
  78. #endif
  79. //////////////////////////////////////////////////////////////////////////
  80. // Searchable
  81. //////////////////////////////////////////////////////////////////////////
  82. #ifdef BOOST_HANA_TEST_SEARCHABLE
  83. {
  84. hana::test::TestSearchable<::Seq>{eqs, eq_keys};
  85. auto bools = hana::make_tuple(
  86. ::seq(hana::true_c)
  87. , ::seq(hana::false_c)
  88. , ::seq(hana::true_c, hana::true_c)
  89. , ::seq(hana::true_c, hana::false_c)
  90. , ::seq(hana::false_c, hana::true_c)
  91. , ::seq(hana::false_c, hana::false_c)
  92. );
  93. hana::test::TestSearchable<::Seq>{bools, hana::make_tuple(hana::true_c, hana::false_c)};
  94. }
  95. #endif
  96. //////////////////////////////////////////////////////////////////////////
  97. // Functor, Applicative, Monad
  98. //////////////////////////////////////////////////////////////////////////
  99. #ifdef BOOST_HANA_TEST_MONAD
  100. hana::test::TestFunctor<::Seq>{eqs, eq_keys};
  101. hana::test::TestApplicative<::Seq>{eqs};
  102. hana::test::TestMonad<::Seq>{eqs, nested_eqs};
  103. #endif
  104. //////////////////////////////////////////////////////////////////////////
  105. // MonadPlus
  106. //////////////////////////////////////////////////////////////////////////
  107. #ifdef BOOST_HANA_TEST_MONAD_PLUS
  108. hana::test::TestMonadPlus<::Seq>{eqs, predicates, eq_keys};
  109. #endif
  110. //////////////////////////////////////////////////////////////////////////
  111. // Sequence
  112. //////////////////////////////////////////////////////////////////////////
  113. #ifdef BOOST_HANA_TEST_SEQUENCE
  114. hana::test::TestSequence<::Seq>{};
  115. #endif
  116. }