laws.cpp 2.0 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/detail/canonical_constant.hpp>
  5. #include <boost/hana/tuple.hpp>
  6. #include <laws/comparable.hpp>
  7. #include <laws/constant.hpp>
  8. #include <laws/euclidean_ring.hpp>
  9. #include <laws/group.hpp>
  10. #include <laws/logical.hpp>
  11. #include <laws/monoid.hpp>
  12. #include <laws/orderable.hpp>
  13. #include <laws/ring.hpp>
  14. namespace hana = boost::hana;
  15. template <typename T, T v>
  16. struct canonical {
  17. static constexpr T value = v;
  18. using hana_tag = hana::detail::CanonicalConstant<T>;
  19. };
  20. int main() {
  21. auto ints = hana::make_tuple(
  22. canonical<int, -10>{}, canonical<int, -2>{}, canonical<int, 0>{},
  23. canonical<int, 1>{}, canonical<int, 3>{}, canonical<int, 4>{}
  24. );
  25. auto bools = hana::make_tuple(canonical<bool, true>{}, canonical<bool, false>{});
  26. // Constant
  27. hana::test::TestConstant<hana::detail::CanonicalConstant<int>>{ints, hana::tuple_t<int, long, long long>};
  28. hana::test::TestConstant<hana::detail::CanonicalConstant<bool>>{bools, hana::tuple_t<bool>};
  29. // Monoid, Group, Ring, EuclideanRing
  30. hana::test::TestMonoid<hana::detail::CanonicalConstant<int>>{ints};
  31. hana::test::TestGroup<hana::detail::CanonicalConstant<int>>{ints};
  32. hana::test::TestRing<hana::detail::CanonicalConstant<int>>{ints};
  33. hana::test::TestEuclideanRing<hana::detail::CanonicalConstant<int>>{ints};
  34. // Logical
  35. {
  36. auto ints = hana::make_tuple(
  37. canonical<int, -2>{}, canonical<int, 0>{},
  38. canonical<int, 1>{}, canonical<int, 3>{}
  39. );
  40. hana::test::TestLogical<hana::detail::CanonicalConstant<int>>{ints};
  41. hana::test::TestLogical<hana::detail::CanonicalConstant<bool>>{bools};
  42. }
  43. // Comparable and Orderable
  44. hana::test::TestComparable<hana::detail::CanonicalConstant<int>>{ints};
  45. hana::test::TestOrderable<hana::detail::CanonicalConstant<int>>{ints};
  46. }