laws.functor.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/bool.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/functional/always.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. #include <laws/applicative.hpp>
  9. #include <laws/base.hpp>
  10. #include <laws/functor.hpp>
  11. #include <laws/monad.hpp>
  12. #include <laws/monad_plus.hpp>
  13. namespace hana = boost::hana;
  14. using hana::test::ct_eq;
  15. int main() {
  16. auto eq_tuples = hana::make_tuple(
  17. hana::make_tuple()
  18. , hana::make_tuple(ct_eq<0>{})
  19. , hana::make_tuple(ct_eq<0>{}, ct_eq<1>{})
  20. , hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  21. , hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{})
  22. , hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{})
  23. , hana::make_tuple(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}, ct_eq<4>{}, ct_eq<5>{})
  24. );
  25. auto eq_values = hana::make_tuple(
  26. ct_eq<0>{},
  27. ct_eq<2>{},
  28. ct_eq<4>{}
  29. );
  30. auto predicates = hana::make_tuple(
  31. hana::equal.to(ct_eq<0>{}),
  32. hana::equal.to(ct_eq<2>{}),
  33. hana::equal.to(ct_eq<4>{}),
  34. hana::always(hana::true_c),
  35. hana::always(hana::false_c)
  36. );
  37. auto nested_eqs = hana::make_tuple(
  38. hana::make_tuple()
  39. , hana::make_tuple(
  40. hana::make_tuple(ct_eq<0>{})
  41. )
  42. , hana::make_tuple(
  43. hana::make_tuple(ct_eq<0>{}),
  44. hana::make_tuple(ct_eq<1>{}, ct_eq<2>{})
  45. )
  46. , hana::make_tuple(
  47. hana::make_tuple(ct_eq<0>{}),
  48. hana::make_tuple(ct_eq<1>{}, ct_eq<2>{}),
  49. hana::make_tuple(ct_eq<3>{}, ct_eq<4>{})
  50. )
  51. );
  52. hana::test::TestFunctor<hana::tuple_tag>{eq_tuples, eq_values};
  53. hana::test::TestApplicative<hana::tuple_tag>{eq_tuples};
  54. hana::test::TestMonad<hana::tuple_tag>{eq_tuples, nested_eqs};
  55. hana::test::TestMonadPlus<hana::tuple_tag>{eq_tuples, predicates, eq_values};
  56. }