1 // Copyright Louis Dionne 2013-2016
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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/config.hpp>
7 #include <boost/hana/contains.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/if.hpp>
10 #include <boost/hana/monadic_compose.hpp>
11 #include <boost/hana/optional.hpp>
12 #include <boost/hana/tuple.hpp>
13 #include <boost/hana/type.hpp>
14 namespace hana
= boost::hana
;
18 BOOST_HANA_CONSTEXPR_LAMBDA
auto block
= [](auto ...types
) {
20 return hana::if_(hana::contains(hana::make_tuple(types
...), hana::typeid_(x
)),
27 BOOST_HANA_CONSTEXPR_LAMBDA
auto f
= block(hana::type_c
<double>);
28 BOOST_HANA_CONSTEXPR_LAMBDA
auto g
= block(hana::type_c
<int>);
29 BOOST_HANA_CONSTEXPR_LAMBDA
auto h
= hana::monadic_compose(g
, f
);
30 BOOST_HANA_CONSTANT_CHECK(h(1) == hana::nothing
); // fails inside g; 1 has type int
31 BOOST_HANA_CONSTANT_CHECK(h(1.2) == hana::nothing
); // fails inside f; 1.2 has type double
32 BOOST_HANA_CONSTEXPR_CHECK(h('x') == hana::just('x')); // ok; 'x' has type char