|
Boost Users : |
Subject: Re: [Boost-users] [Boost.Hana] how to merge two or more maps
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2016-08-24 21:06:46
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 <boost/hana.hpp>
#include <string>
namespace hana = boost::hana;
using namespace hana::literals;
constexpr auto m1 = hana::make_map(
hana::make_pair("key1"_s, hana::type_c<std::string>),
hana::make_pair("key2"_s, hana::type_c<std::string>)
);
constexpr auto m2 = hana::make_map(
hana::make_pair("key3"_s, hana::type_c<std::string>),
hana::make_pair("key4"_s, hana::type_c<std::string>),
hana::make_pair("key5"_s, hana::type_c<std::string>)
);
constexpr auto result = hana::fold_left(m1, m2, hana::insert);
constexpr auto expected = hana::make_map(
hana::make_pair("key1"_s, hana::type_c<std::string>),
hana::make_pair("key2"_s, hana::type_c<std::string>),
hana::make_pair("key3"_s, hana::type_c<std::string>),
hana::make_pair("key4"_s, hana::type_c<std::string>),
hana::make_pair("key5"_s, hana::type_c<std::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-tp4687834p4687856.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net