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/chain.hpp>
7 #include <boost/hana/equal.hpp>
8 #include <boost/hana/optional.hpp>
9 
10 #include <laws/base.hpp>
11 #include <support/tracked.hpp>
12 namespace hana = boost::hana;
13 using hana::test::ct_eq;
14 
15 
16 struct undefined { };
17 
main()18 int main() {
19     hana::test::_injection<0> f{};
20 
21     BOOST_HANA_CONSTANT_CHECK(hana::equal(
22         hana::sfinae(f)(),
23         hana::just(f())
24     ));
25 
26     BOOST_HANA_CONSTANT_CHECK(hana::equal(
27         hana::sfinae(f)(ct_eq<0>{}),
28         hana::just(f(ct_eq<0>{}))
29     ));
30 
31     BOOST_HANA_CONSTANT_CHECK(hana::equal(
32         hana::sfinae(f)(ct_eq<0>{}, ct_eq<1>{}),
33         hana::just(f(ct_eq<0>{}, ct_eq<1>{}))
34     ));
35 
36     BOOST_HANA_CONSTANT_CHECK(hana::equal(
37         hana::sfinae(undefined{})(),
38         hana::nothing
39     ));
40 
41     BOOST_HANA_CONSTANT_CHECK(hana::equal(
42         hana::sfinae(undefined{})(ct_eq<0>{}),
43         hana::nothing
44     ));
45 
46     BOOST_HANA_CONSTANT_CHECK(hana::equal(
47         hana::sfinae(undefined{})(ct_eq<0>{}, ct_eq<1>{}),
48         hana::nothing
49     ));
50 
51     auto incr = hana::sfinae([](auto x) -> decltype(x + 1) {
52         return x + 1;
53     });
54 
55     BOOST_HANA_RUNTIME_CHECK(hana::equal(
56         incr(1),
57         hana::just(2)
58     ));
59     BOOST_HANA_CONSTANT_CHECK(hana::equal(
60         incr(undefined{}),
61         hana::nothing
62     ));
63     BOOST_HANA_RUNTIME_CHECK(hana::equal(
64         hana::chain(hana::just(1), incr),
65         hana::just(2)
66     ));
67 
68     // using `sfinae` with a non-pod argument used to fail
69     hana::sfinae(undefined{})(Tracked{1});
70     hana::sfinae([t = Tracked{1}](auto) { return 1; })(Tracked{1});
71 }
72