[Boost.Hana] how to merge two or more maps
Hi,
I am looking into the documentation of hana to merge two or more maps, say:
#include
Hana does not provide a way to merge two maps out of the box, although that
would be very useful. I added a feature request at [1]. For now, you can use
`fold_left` with `insert` to insert each element of the
#include
Thank you for your answer. Regards, Matthijs On 8/25/16 3:06 AM, Louis Dionne wrote:
Hana does not provide a way to merge two maps out of the box, although that would be very useful. I added a feature request at [1]. For now, you can use `fold_left` with `insert` to insert each element of the
#include
#include <string> namespace hana = boost::hana; using namespace hana::literals; constexpr auto m1 = hana::make_map( hana::make_pair("key1"_s, hana::type_cstd::string), hana::make_pair("key2"_s, hana::type_cstd::string) );
constexpr auto m2 = hana::make_map( hana::make_pair("key3"_s, hana::type_cstd::string), hana::make_pair("key4"_s, hana::type_cstd::string), hana::make_pair("key5"_s, hana::type_cstd::string) );
constexpr auto result = hana::fold_left(m1, m2, hana::insert); constexpr auto expected = hana::make_map( hana::make_pair("key1"_s, hana::type_cstd::string), hana::make_pair("key2"_s, hana::type_cstd::string), hana::make_pair("key3"_s, hana::type_cstd::string), hana::make_pair("key4"_s, hana::type_cstd::string), hana::make_pair("key5"_s, hana::type_cstd::string) );
static_assert(result == expected, "");
int main() { }
Also, while posting on this list is OK, please note that the preferred way to ask Hana-related questions is on StackOverflow with the [boost-hana] tag, as documented at [2]. This allows everybody to benefit from questions and answers, and I am registered to the tag so there's no chance that I miss your question as on this list.
Regards, Louis
[1]: https://github.com/boostorg/hana/issues/299 [2]: http://boostorg.github.io/hana/#tutorial-support
-- View this message in context: http://boost.2283326.n4.nabble.com/Boost-Hana-how-to-merge-two-or-more-maps-... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Louis Dionne
-
Matthijs Möhlmann