| 1 | // Copyright Louis Dionne 2013-2022 |
| 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) |
| 4 | |
| 5 | #include <boost/hana/accessors.hpp> |
| 6 | #include <boost/hana/all_of.hpp> |
| 7 | #include <boost/hana/assert.hpp> |
| 8 | #include <boost/hana/define_struct.hpp> |
| 9 | #include <boost/hana/equal.hpp> |
| 10 | #include <boost/hana/find.hpp> |
| 11 | #include <boost/hana/optional.hpp> |
| 12 | #include <boost/hana/second.hpp> |
| 13 | #include <boost/hana/string.hpp> |
| 14 | |
| 15 | #include <string> |
| 16 | namespace hana = boost::hana; |
| 17 | |
| 18 | |
| 19 | struct Person { |
| 20 | BOOST_HANA_DEFINE_STRUCT(Person, |
| 21 | (std::string, name), |
| 22 | (unsigned short, age) |
| 23 | ); |
| 24 | }; |
| 25 | |
| 26 | int main() { |
| 27 | Person john{.name: "John" , .age: 30}; |
| 28 | |
| 29 | BOOST_HANA_RUNTIME_CHECK( |
| 30 | hana::find(john, BOOST_HANA_STRING("name" )) == hana::just("John" ) |
| 31 | ); |
| 32 | |
| 33 | BOOST_HANA_CONSTANT_CHECK( |
| 34 | hana::find(john, BOOST_HANA_STRING("foobar" )) == hana::nothing |
| 35 | ); |
| 36 | |
| 37 | |
| 38 | BOOST_HANA_RUNTIME_CHECK( |
| 39 | hana::all_of(hana::accessors<Person>(), [&](auto a) { |
| 40 | return hana::second(a)(john) == hana::second(a)(john); |
| 41 | }) |
| 42 | ); |
| 43 | |
| 44 | // the above is equivalent to: |
| 45 | BOOST_HANA_RUNTIME_CHECK(hana::equal(john, john)); |
| 46 | } |
| 47 | |