demux.cpp 1.9 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/assert.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/functional/demux.hpp>
  7. #include <laws/base.hpp>
  8. namespace hana = boost::hana;
  9. using hana::test::ct_eq;
  10. struct MoveOnly {
  11. MoveOnly() = default;
  12. MoveOnly(MoveOnly const&) = delete;
  13. MoveOnly(MoveOnly&&) = default;
  14. };
  15. int main() {
  16. hana::test::_injection<0> f{};
  17. hana::test::_injection<1> g{};
  18. hana::test::_injection<2> h{};
  19. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  20. hana::demux(f)()(),
  21. f()
  22. ));
  23. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  24. hana::demux(f)(g)(ct_eq<1>{}),
  25. f(g(ct_eq<1>{}))
  26. ));
  27. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  28. hana::demux(f)(g)(ct_eq<1>{}, ct_eq<2>{}),
  29. f(g(ct_eq<1>{}, ct_eq<2>{}))
  30. ));
  31. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  32. hana::demux(f)(g)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}),
  33. f(g(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}))
  34. ));
  35. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  36. hana::demux(f)(g, h)(ct_eq<1>{}),
  37. f(g(ct_eq<1>{}), h(ct_eq<1>{}))
  38. ));
  39. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  40. hana::demux(f)(g, h)(ct_eq<1>{}, ct_eq<2>{}),
  41. f(g(ct_eq<1>{}, ct_eq<2>{}), h(ct_eq<1>{}, ct_eq<2>{}))
  42. ));
  43. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  44. hana::demux(f)(g, h)(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}),
  45. f(g(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}), h(ct_eq<1>{}, ct_eq<2>{}, ct_eq<3>{}))
  46. ));
  47. // Make sure we can pass move-only types when a single function
  48. // is demux'ed. In other words, make sure the arguments are
  49. // perfect-forwarded when a single function is demux'ed.
  50. {
  51. hana::demux(f)(g)(MoveOnly{});
  52. hana::demux(f)(g)(MoveOnly{}, MoveOnly{});
  53. hana::demux(f)(g)(MoveOnly{}, MoveOnly{}, MoveOnly{});
  54. }
  55. }