logical.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/ext/std/integral_constant.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/eval_if.hpp>
  8. #include <boost/hana/functional/always.hpp>
  9. #include <boost/hana/integral_constant.hpp>
  10. #include <boost/hana/not.hpp>
  11. #include <boost/hana/tuple.hpp>
  12. #include <laws/base.hpp>
  13. #include <laws/logical.hpp>
  14. #include <type_traits>
  15. namespace hana = boost::hana;
  16. int main() {
  17. // eval_if
  18. {
  19. auto t = hana::test::ct_eq<3>{};
  20. auto e = hana::test::ct_eq<4>{};
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  22. hana::eval_if(std::true_type{}, hana::always(t), hana::always(e)),
  23. t
  24. ));
  25. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  26. hana::eval_if(std::false_type{}, hana::always(t), hana::always(e)),
  27. e
  28. ));
  29. }
  30. // not_
  31. {
  32. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  33. hana::not_(std::true_type{}),
  34. std::false_type{}
  35. ));
  36. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  37. hana::not_(std::false_type{}),
  38. std::true_type{}
  39. ));
  40. }
  41. auto ints = hana::make_tuple(
  42. std::integral_constant<int, -2>{},
  43. std::integral_constant<int, 0>{},
  44. std::integral_constant<int, 1>{},
  45. std::integral_constant<int, 3>{}
  46. );
  47. auto bools = hana::make_tuple(std::true_type{}, std::false_type{});
  48. // laws
  49. hana::test::TestLogical<hana::ext::std::integral_constant_tag<int>>{ints};
  50. hana::test::TestLogical<hana::ext::std::integral_constant_tag<bool>>{bools};
  51. }