ap.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/ap.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/experimental/view.hpp>
  8. #include <boost/hana/functional/id.hpp>
  9. #include <laws/base.hpp>
  10. #include <support/seq.hpp>
  11. namespace hana = boost::hana;
  12. using hana::test::_injection;
  13. using hana::test::ct_eq;
  14. int main() {
  15. auto container = ::seq;
  16. auto f = hana::test::_injection<99>{};
  17. {
  18. auto storage = container();
  19. auto functions = container();
  20. auto transformed_storage = hana::experimental::transformed(storage, f);
  21. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. hana::ap(transformed_functions, transformed_storage),
  24. container()
  25. ));
  26. }{
  27. auto storage = container(ct_eq<0>{});
  28. auto functions = container();
  29. auto transformed_storage = hana::experimental::transformed(storage, f);
  30. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  31. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  32. hana::ap(transformed_functions, transformed_storage),
  33. container()
  34. ));
  35. }{
  36. auto storage = container();
  37. auto functions = container(ct_eq<0>{});
  38. auto transformed_storage = hana::experimental::transformed(storage, f);
  39. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  40. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  41. hana::ap(transformed_functions, transformed_storage),
  42. container()
  43. ));
  44. }
  45. {
  46. auto storage = container(ct_eq<0>{});
  47. auto functions = container(_injection<0>{});
  48. auto transformed_storage = hana::experimental::transformed(storage, f);
  49. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  50. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  51. hana::ap(transformed_functions, transformed_storage),
  52. container(_injection<0>{}(f(ct_eq<0>{})))
  53. ));
  54. }{
  55. auto storage = container(ct_eq<0>{});
  56. auto functions = container(_injection<0>{}, _injection<1>{});
  57. auto transformed_storage = hana::experimental::transformed(storage, f);
  58. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  59. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  60. hana::ap(transformed_functions, transformed_storage),
  61. container(_injection<0>{}(f(ct_eq<0>{})),
  62. _injection<1>{}(f(ct_eq<0>{})))
  63. ));
  64. }{
  65. auto storage = container(ct_eq<0>{});
  66. auto functions = container(_injection<0>{}, _injection<1>{}, _injection<2>{});
  67. auto transformed_storage = hana::experimental::transformed(storage, f);
  68. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  69. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  70. hana::ap(transformed_functions, transformed_storage),
  71. container(_injection<0>{}(f(ct_eq<0>{})),
  72. _injection<1>{}(f(ct_eq<0>{})),
  73. _injection<2>{}(f(ct_eq<0>{})))
  74. ));
  75. }
  76. {
  77. auto storage = container(ct_eq<0>{}, ct_eq<1>{});
  78. auto functions = container(_injection<0>{});
  79. auto transformed_storage = hana::experimental::transformed(storage, f);
  80. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  81. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  82. hana::ap(transformed_functions, transformed_storage),
  83. container(_injection<0>{}(f(ct_eq<0>{})),
  84. _injection<0>{}(f(ct_eq<1>{})))
  85. ));
  86. }{
  87. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  88. auto functions = container(_injection<0>{});
  89. auto transformed_storage = hana::experimental::transformed(storage, f);
  90. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  91. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  92. hana::ap(transformed_functions, transformed_storage),
  93. container(_injection<0>{}(f(ct_eq<0>{})),
  94. _injection<0>{}(f(ct_eq<1>{})),
  95. _injection<0>{}(f(ct_eq<2>{})))
  96. ));
  97. }
  98. {
  99. auto storage = container(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{});
  100. auto functions = container(_injection<0>{}, _injection<1>{});
  101. auto transformed_storage = hana::experimental::transformed(storage, f);
  102. auto transformed_functions = hana::experimental::transformed(functions, hana::id);
  103. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  104. hana::ap(transformed_functions, transformed_storage),
  105. container(_injection<0>{}(f(ct_eq<0>{})),
  106. _injection<0>{}(f(ct_eq<1>{})),
  107. _injection<0>{}(f(ct_eq<2>{})),
  108. _injection<1>{}(f(ct_eq<0>{})),
  109. _injection<1>{}(f(ct_eq<1>{})),
  110. _injection<1>{}(f(ct_eq<2>{})))
  111. ));
  112. }
  113. }