equal.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/core/to.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/for_each.hpp>
  8. #include <boost/hana/not.hpp>
  9. #include <boost/hana/not_equal.hpp> // for operator !=
  10. #include <boost/hana/permutations.hpp>
  11. #include <boost/hana/set.hpp>
  12. #include <boost/hana/tuple.hpp>
  13. #include <laws/base.hpp>
  14. namespace hana = boost::hana;
  15. using hana::test::ct_eq;
  16. int main() {
  17. auto check = [](auto ...keys) {
  18. auto keys_set = hana::make_set(keys...);
  19. auto keys_tuple = hana::make_tuple(keys...);
  20. auto possible_arrangements = hana::permutations(keys_tuple);
  21. hana::for_each(possible_arrangements, [&](auto perm) {
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. hana::to_set(perm),
  24. keys_set
  25. ));
  26. });
  27. BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(
  28. keys_set,
  29. hana::make_set(keys..., ct_eq<999>{})
  30. )));
  31. };
  32. check();
  33. check(ct_eq<0>{});
  34. check(ct_eq<0>{}, ct_eq<1>{});
  35. check(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  36. // check operators
  37. BOOST_HANA_CONSTANT_CHECK(
  38. hana::make_set(ct_eq<0>{})
  39. ==
  40. hana::make_set(ct_eq<0>{})
  41. );
  42. BOOST_HANA_CONSTANT_CHECK(
  43. hana::make_set(ct_eq<0>{})
  44. !=
  45. hana::make_set(ct_eq<1>{})
  46. );
  47. }