2
0
mirror of https://github.com/boostorg/hana.git synced 2026-02-02 08:52:11 +00:00

[Map] Provide model of Foldable, improve docs and add insert method.

Fixes #41
This commit is contained in:
Louis Dionne
2015-04-11 10:38:52 -04:00
parent 8bd84a5d4b
commit daaba5dfd8
11 changed files with 701 additions and 385 deletions

View File

@@ -0,0 +1,44 @@
/*
@copyright Louis Dionne 2015
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#include <boost/hana/assert.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/map.hpp>
#include <boost/hana/pair.hpp>
#include <boost/hana/string.hpp>
#include <boost/hana/tuple.hpp>
#include <string>
using namespace boost::hana;
//! [main]
struct Person {
std::string name;
int age;
struct hana { struct members_impl {
static BOOST_HANA_CONSTEXPR_LAMBDA auto apply() {
return make<Tuple>(
make<Pair>(BOOST_HANA_STRING("name"), [](auto&& p) {
return p.name;
}),
make<Pair>(BOOST_HANA_STRING("age"), [](auto&& p) {
return p.age;
})
);
}
};};
};
int main() {
Person john{"John", 35};
BOOST_HANA_RUNTIME_ASSERT(to<Map>(john) == make<Map>(
make<Pair>(BOOST_HANA_STRING("name"), "John"),
make<Pair>(BOOST_HANA_STRING("age"), 35)
));
}
//! [main]