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/concept/struct.hpp>
7 #include <boost/hana/config.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/find.hpp>
10 #include <boost/hana/functional/id.hpp>
11 #include <boost/hana/integral_constant.hpp>
12 #include <boost/hana/not_equal.hpp>
13 #include <boost/hana/pair.hpp>
14 #include <boost/hana/string.hpp>
15 #include <boost/hana/tuple.hpp>
19 namespace hana
= boost::hana
;
27 struct hana_accessors_impl
{
28 static BOOST_HANA_CONSTEXPR_LAMBDA
auto apply() {
29 return boost::hana::make_tuple(
30 boost::hana::make_pair(BOOST_HANA_STRING("name"),
31 [](auto&& p
) -> decltype(auto) {
32 return boost::hana::id(std::forward
<decltype(p
)>(p
).name
);
34 boost::hana::make_pair(BOOST_HANA_STRING("age"),
35 [](auto&& p
) -> decltype(auto) {
36 return boost::hana::id(std::forward
<decltype(p
)>(p
).age
);
45 Person john
{"John", 30}, bob
{"Bob", 40};
46 BOOST_HANA_RUNTIME_CHECK(hana::equal(john
, john
));
47 BOOST_HANA_RUNTIME_CHECK(hana::not_equal(john
, bob
));
49 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, BOOST_HANA_STRING("name")) == hana::just("John"));
50 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, BOOST_HANA_STRING("age")) == hana::just(30));
51 BOOST_HANA_CONSTANT_CHECK(hana::find(john
, BOOST_HANA_STRING("foo")) == hana::nothing
);
53 BOOST_HANA_RUNTIME_CHECK(hana::to_tuple(john
) == hana::make_tuple(
54 hana::make_pair(BOOST_HANA_STRING("name"), "John"),
55 hana::make_pair(BOOST_HANA_STRING("age"), 30)