minimal_product.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/tuple.hpp>
  5. #include <boost/hana/first.hpp>
  6. #include <boost/hana/second.hpp>
  7. #include <laws/base.hpp>
  8. #include <laws/comparable.hpp>
  9. #include <laws/foldable.hpp>
  10. #include <laws/orderable.hpp>
  11. #include <laws/product.hpp>
  12. #include <support/minimal_product.hpp>
  13. #include <support/tracked.hpp>
  14. #include <utility>
  15. namespace hana = boost::hana;
  16. using hana::test::ct_eq;
  17. using hana::test::ct_ord;
  18. int main() {
  19. // Make sure `first` and `second` are "accessors". If they are not,
  20. // `Tracked` should report a double-move.
  21. {
  22. auto prod = ::minimal_product(::Tracked{1}, ::Tracked{2});
  23. auto fst = hana::first(std::move(prod));
  24. auto snd = hana::second(std::move(prod));
  25. }
  26. //////////////////////////////////////////////////////////////////////////
  27. // Comparable, Orderable, Foldable, Product
  28. //////////////////////////////////////////////////////////////////////////
  29. auto eq_elems = hana::make_tuple(ct_eq<3>{}, ct_eq<4>{});
  30. auto eqs = hana::make_tuple(
  31. ::minimal_product(ct_eq<3>{}, ct_eq<3>{})
  32. , ::minimal_product(ct_eq<3>{}, ct_eq<4>{})
  33. , ::minimal_product(ct_eq<4>{}, ct_eq<3>{})
  34. , ::minimal_product(ct_eq<4>{}, ct_eq<4>{})
  35. );
  36. auto ords = hana::make_tuple(
  37. ::minimal_product(ct_ord<3>{}, ct_ord<3>{})
  38. , ::minimal_product(ct_ord<3>{}, ct_ord<4>{})
  39. , ::minimal_product(ct_ord<4>{}, ct_ord<3>{})
  40. , ::minimal_product(ct_ord<4>{}, ct_ord<4>{})
  41. );
  42. hana::test::TestComparable<::MinimalProduct>{eqs};
  43. hana::test::TestOrderable<::MinimalProduct>{ords};
  44. hana::test::TestFoldable<::MinimalProduct>{eqs};
  45. hana::test::TestProduct<::MinimalProduct>{eq_elems};
  46. }