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/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; 15 16 main()17int main() { 18 BOOST_HANA_CONSTEXPR_LAMBDA auto block = [](auto ...types) { 19 return [=](auto x) { 20 return hana::if_(hana::contains(hana::make_tuple(types...), hana::typeid_(x)), 21 hana::nothing, 22 hana::just(x) 23 ); 24 }; 25 }; 26 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 33 } 34