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)
5 #include <boost/hana/ap.hpp>
6 #include <boost/hana/assert.hpp>
7 #include <boost/hana/bool.hpp>
8 #include <boost/hana/config.hpp>
9 #include <boost/hana/equal.hpp>
10 #include <boost/hana/if.hpp>
11 #include <boost/hana/lift.hpp>
12 #include <boost/hana/optional.hpp>
13 namespace hana
= boost::hana
;
17 constexpr auto function
= hana::nothing
;
20 BOOST_HANA_CONSTEXPR_LAMBDA
auto function
<'+'> = hana::just([](auto x
, auto y
) {
25 BOOST_HANA_CONSTEXPR_LAMBDA
auto function
<'-'> = hana::just([](auto x
, auto y
) {
32 constexpr auto digit
= hana::if_(hana::bool_c
<(n
>= '0' && n
<= '9')>,
33 hana::just(static_cast<int>(n
- 48)),
37 template <char x
, char op
, char y
>
38 BOOST_HANA_CONSTEXPR_LAMBDA
auto evaluate
= hana::ap(function
<op
>, digit
<x
>, digit
<y
>);
41 BOOST_HANA_CONSTEXPR_CHECK(evaluate
<'1', '+', '2'> == hana::just(1 + 2));
42 BOOST_HANA_CONSTEXPR_CHECK(evaluate
<'4', '-', '2'> == hana::just(4 - 2));
44 BOOST_HANA_CONSTANT_CHECK(evaluate
<'?', '+', '2'> == hana::nothing
);
45 BOOST_HANA_CONSTANT_CHECK(evaluate
<'1', '?', '2'> == hana::nothing
);
46 BOOST_HANA_CONSTANT_CHECK(evaluate
<'1', '+', '?'> == hana::nothing
);
47 BOOST_HANA_CONSTANT_CHECK(evaluate
<'?', '?', '?'> == hana::nothing
);
49 static_assert(hana::lift
<hana::optional_tag
>(123) == hana::just(123), "");