1 // Copyright Louis Dionne 2013-2016
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
;
25 Person(std::string
const& name
, int age
) : name_(name
), age_(age
) { }
27 std::string
const& get_name() const { return name_
; }
28 int get_age() const { return age_
; }
35 namespace boost
{ namespace hana
{
37 struct accessors_impl
<Person
> {
38 static BOOST_HANA_CONSTEXPR_LAMBDA
auto apply() {
40 make_pair(BOOST_HANA_STRING("name"), [](auto&& p
) -> std::string
const& {
43 make_pair(BOOST_HANA_STRING("age"), [](auto&& p
) {
53 auto name
= BOOST_HANA_STRING("name");
54 auto age
= BOOST_HANA_STRING("age");
56 Person john
{"John", 30}, bob
{"Bob", 40};
57 BOOST_HANA_RUNTIME_CHECK(hana::equal(john
, john
));
58 BOOST_HANA_RUNTIME_CHECK(hana::not_equal(john
, bob
));
60 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, name
) == hana::just("John"));
61 BOOST_HANA_RUNTIME_CHECK(hana::find(john
, age
) == hana::just(30));
62 BOOST_HANA_CONSTANT_CHECK(hana::find(john
, BOOST_HANA_STRING("foo")) == hana::nothing
);
64 BOOST_HANA_RUNTIME_CHECK(hana::to_tuple(john
) == hana::make_tuple(
65 hana::make_pair(name
, "John"),
66 hana::make_pair(age
, 30)