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