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/assert.hpp>
6 #include <boost/hana/chain.hpp>
7 #include <boost/hana/config.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/optional.hpp>
10 namespace hana
= boost::hana
;
13 BOOST_HANA_CONSTEXPR_LAMBDA
auto deref
= [](auto x
) -> decltype(*x
) {
17 BOOST_HANA_CONSTEXPR_LAMBDA
auto age
= [](auto x
) -> decltype(x
.age
) {
21 BOOST_HANA_CONSTEXPR_LAMBDA
auto f
= [](auto x
) {
22 return hana::chain(hana::sfinae(deref
)(x
), hana::sfinae(age
));
31 constexpr Person john
{30};
33 // Can't dereference a non-pointer.
34 BOOST_HANA_CONSTANT_CHECK(f(john
) == hana::nothing
);
36 // `int` has no member named `age`.
37 BOOST_HANA_CONSTANT_CHECK(f(1) == hana::nothing
);
40 BOOST_HANA_CONSTEXPR_CHECK(f(&john
) == hana::just(30u));