How can I emplace to std::map<std::string, std::map<std::string,std::string>>?
tried with myMap.emplace(std::make_pair("STRING", std::make_pair("STR","STR"))) but got error message cannot convert std::pair<_Ty1,_Ty2> to const std::pair<_Ty1,_Ty2>
myMap.emplace(
std::make_pair(
"STR1"
, std::map< std::string, std::string>(
{
std::make_pair("STR2", "STR3")
}
)
)
);
Should work.
Using std::piecewise_construct you can emplace() as follows
myMap.emplace(
std::piecewise_construct,
std::forward_as_tuple("STRING"),
std::forward_as_tuple(
std::initializer_list<std::pair<std::string const, std::string>>{
{"STR", "STR"} }));
but I think it's a little clearer emplace an empty map and immediatly after emplace the "STR"s in it, as follows
myMap.emplace(std::piecewise_construct,
std::forward_as_tuple("STRING"),
std::forward_as_tuple()).first->second.emplace("STR", "STR");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With