]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/concept/struct/at_key.cpp
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/at_key.hpp>
7 #include <boost/hana/define_struct.hpp>
8 #include <boost/hana/string.hpp>
11 namespace hana
= boost::hana
;
15 BOOST_HANA_DEFINE_STRUCT(Person
,
17 (std::string
, last_name
),
25 Person john
{"John", "Doe", 30};
26 std::string
& name
= hana::at_key(john
, BOOST_HANA_STRING("name"));
27 std::string
& last_name
= hana::at_key(john
, BOOST_HANA_STRING("last_name"));
28 int& age
= hana::at_key(john
, BOOST_HANA_STRING("age"));
34 BOOST_HANA_RUNTIME_CHECK(john
.name
== "Bob");
35 BOOST_HANA_RUNTIME_CHECK(john
.last_name
== "Foo");
36 BOOST_HANA_RUNTIME_CHECK(john
.age
== 99);
41 Person john
{"John", "Doe", 30};
42 Person
const& const_john
= john
;
43 std::string
const& name
= hana::at_key(const_john
, BOOST_HANA_STRING("name"));
44 std::string
const& last_name
= hana::at_key(const_john
, BOOST_HANA_STRING("last_name"));
45 int const& age
= hana::at_key(const_john
, BOOST_HANA_STRING("age"));
48 john
.last_name
= "Foo";
51 BOOST_HANA_RUNTIME_CHECK(name
== "Bob");
52 BOOST_HANA_RUNTIME_CHECK(last_name
== "Foo");
53 BOOST_HANA_RUNTIME_CHECK(age
== 99);