capture.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/assert.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/functional/capture.hpp>
  7. #include <laws/base.hpp>
  8. namespace hana = boost::hana;
  9. using hana::test::ct_eq;
  10. int main() {
  11. hana::test::_injection<0> f{};
  12. // 0-arg capture
  13. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  14. hana::capture()(f)(),
  15. f()
  16. ));
  17. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  18. hana::capture()(f)(ct_eq<0>{}),
  19. f(ct_eq<0>{})
  20. ));
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  22. hana::capture()(f)(ct_eq<0>{}, ct_eq<1>{}),
  23. f(ct_eq<0>{}, ct_eq<1>{})
  24. ));
  25. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  26. hana::capture()(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
  27. f(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  28. ));
  29. // 1-arg capture
  30. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  31. hana::capture(ct_eq<77>{})(f)(),
  32. f(ct_eq<77>{})
  33. ));
  34. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  35. hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}),
  36. f(ct_eq<77>{}, ct_eq<0>{})
  37. ));
  38. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  39. hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}, ct_eq<1>{}),
  40. f(ct_eq<77>{}, ct_eq<0>{}, ct_eq<1>{})
  41. ));
  42. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  43. hana::capture(ct_eq<77>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
  44. f(ct_eq<77>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  45. ));
  46. // 2-args capture
  47. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  48. hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(),
  49. f(ct_eq<77>{}, ct_eq<88>{})
  50. ));
  51. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  52. hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}),
  53. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{})
  54. ));
  55. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  56. hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}, ct_eq<1>{}),
  57. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{}, ct_eq<1>{})
  58. ));
  59. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  60. hana::capture(ct_eq<77>{}, ct_eq<88>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
  61. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  62. ));
  63. // 3-args capture
  64. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  65. hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(),
  66. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})
  67. ));
  68. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  69. hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}),
  70. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{})
  71. ));
  72. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  73. hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}, ct_eq<1>{}),
  74. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{}, ct_eq<1>{})
  75. ));
  76. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  77. hana::capture(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{})(f)(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
  78. f(ct_eq<77>{}, ct_eq<88>{}, ct_eq<99>{}, ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{})
  79. ));
  80. }