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/config.hpp>
7 #include <boost/hana/core/to.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/find.hpp>
10 #include <boost/hana/functional/id.hpp>
11 #include <boost/hana/fwd/accessors.hpp>
12 #include <boost/hana/integral_constant.hpp>
13 #include <boost/hana/not_equal.hpp>
14 #include <boost/hana/pair.hpp>
15 #include <boost/hana/string.hpp>
16 #include <boost/hana/tuple.hpp>
20 namespace hana
= boost::hana
;
29 // The keys can be anything as long as they are compile-time comparable.
30 constexpr auto name
= hana::integral_c
<std::string
Person::*, &Person::name
>;
31 constexpr auto age
= hana::string_c
<'a', 'g', 'e'>;
33 namespace boost
{ namespace hana
{
35 struct accessors_impl
<Person
> {
36 static BOOST_HANA_CONSTEXPR_LAMBDA
auto apply() {
38 make_pair(name
, [](auto&& p
) -> decltype(auto) {
39 return id(std::forward
<decltype(p
)>(p
).name
);
41 make_pair(age
, [](auto&& p
) -> decltype(auto) {
42 return id(std::forward
<decltype(p
)>(p
).age
);
51 Person john
{"John", 30}, bob
{"Bob", 40};
52 BOOST_HANA_RUNTIME_CHECK(hana::equal(john
, john
));
53 BOOST_HANA_RUNTIME_CHECK(hana::not_equal(john
, bob
));
55 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, name
) == hana::just("John"));
56 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, age
) == hana::just(30));
57 BOOST_HANA_CONSTANT_CHECK(hana::find(john
, BOOST_HANA_STRING("foo")) == hana::nothing
);
59 BOOST_HANA_RUNTIME_CHECK(hana::to_tuple(john
) == hana::make_tuple(
60 hana::make_pair(name
, "John"),
61 hana::make_pair(age
, 30)