Ich habe das schon auf der Boost-Mailingliste gefragt, aber ich war mir nicht so sicher, was meine Absichten waren. Es könnte mir auch nicht ganz klar sein, wie ich das erreichen kann.Mehrere Karten zusammenfügen
ich mehrere Karten in hana finden Sie im folgenden Codebeispiel zusammenführen möchten:
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 m3 = hana::make_map(
hana::make_pair("key6"_s, hana::type_c<std::string>),
hana::make_pair("key7"_s, hana::type_c<std::string>),
hana::make_pair("key8"_s, hana::type_c<std::string>)
);
Ich habe bereits eine Antwort, wie dies zu tun für zwei Karten:
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>)
);
Als ich das geprüft Dokumentation kann ich sehen, dass fold_left 2 oder 3 Argumente benötigt.
Es sieht aus wie ich brauche so etwas wie: fold_left (fold_left (m1, m3, hana :: einfügen), m2, hana :: einfügen);
template<typename Map...>
constexpr auto merge_multiple_maps(Map... args) {
// do something useful here...
}
Aber ich bin nicht sicher, wie hier verfahren und ich habe noch nicht so viel Erfahrung in der Meta-Programmierung ...
Grüße, Matthijs
Sollte nicht 'std vorwärts :: (m1) 'Arbeit, zur Selbstdokumentation? –
Quentin
Ja, tut mir leid. Ich habe die Angewohnheit, 'static_cast' in Hana's Implementierung zu verwenden, weil es 1 weniger Funktionsinstanziierung verursacht (und das macht einen Unterschied in Hana), aber ich werde meine Antwort bearbeiten, weil' std :: forward' klarer ist. –