to.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/assert.hpp>
  5. #include <boost/hana/contains.hpp>
  6. #include <boost/hana/core/to.hpp>
  7. #include <boost/hana/equal.hpp>
  8. #include <boost/hana/permutations.hpp>
  9. #include <boost/hana/set.hpp>
  10. #include <laws/base.hpp>
  11. #include <support/seq.hpp>
  12. namespace hana = boost::hana;
  13. using hana::test::ct_eq;
  14. int main() {
  15. auto sequence = ::seq;
  16. auto foldable = ::seq;
  17. using S = ::Seq;
  18. // Set -> Sequence
  19. {
  20. auto check = [=](auto ...xs) {
  21. BOOST_HANA_CONSTANT_CHECK(hana::contains(
  22. hana::permutations(sequence(xs...)),
  23. hana::to<S>(hana::make_set(xs...))
  24. ));
  25. };
  26. check();
  27. check(ct_eq<1>{});
  28. check(ct_eq<1>{}, ct_eq<2>{});
  29. check(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{});
  30. check(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{});
  31. }
  32. // Foldable -> Set
  33. {
  34. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  35. hana::to<hana::set_tag>(foldable()),
  36. hana::make_set()
  37. ));
  38. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  39. hana::to<hana::set_tag>(foldable(ct_eq<1>{})),
  40. hana::make_set(ct_eq<1>{})
  41. ));
  42. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  43. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<1>{})),
  44. hana::make_set(ct_eq<1>{})
  45. ));
  46. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  47. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{})),
  48. hana::make_set(ct_eq<1>{}, ct_eq<2>{})
  49. ));
  50. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  51. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<1>{})),
  52. hana::make_set(ct_eq<1>{}, ct_eq<2>{})
  53. ));
  54. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  55. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<2>{})),
  56. hana::make_set(ct_eq<1>{}, ct_eq<2>{})
  57. ));
  58. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  59. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})),
  60. hana::make_set(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})
  61. ));
  62. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  63. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<2>{}, ct_eq<1>{})),
  64. hana::make_set(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})
  65. ));
  66. }
  67. // to_set == to<set_tag>
  68. {
  69. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  70. hana::to_set(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<2>{}, ct_eq<1>{})),
  71. hana::to<hana::set_tag>(foldable(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<2>{}, ct_eq<1>{}))
  72. ));
  73. }
  74. }