]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/example/accessors.cpp
49720e54c53aea968fb733648a8b4e6e861c4b0b
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/accessors.hpp>
6 #include <boost/hana/assert.hpp>
7 #include <boost/hana/at.hpp>
8 #include <boost/hana/define_struct.hpp>
9 #include <boost/hana/equal.hpp>
10 #include <boost/hana/first.hpp>
11 #include <boost/hana/integral_constant.hpp>
12 #include <boost/hana/second.hpp>
13 #include <boost/hana/string.hpp>
16 namespace hana
= boost::hana
;
20 BOOST_HANA_DEFINE_STRUCT(Person
,
27 constexpr auto accessors
= hana::accessors
<Person
>();
28 BOOST_HANA_CONSTANT_CHECK(
29 hana::first(accessors
[hana::size_c
<0>]) == BOOST_HANA_STRING("name")
32 BOOST_HANA_CONSTANT_CHECK(
33 hana::first(accessors
[hana::size_c
<1>]) == BOOST_HANA_STRING("age")
36 constexpr auto get_name
= hana::second(accessors
[hana::size_c
<0>]);
37 constexpr auto get_age
= hana::second(accessors
[hana::size_c
<1>]);
39 Person john
{"John", 30};
40 BOOST_HANA_RUNTIME_CHECK(get_name(john
) == "John");
41 BOOST_HANA_RUNTIME_CHECK(get_age(john
) == 30);