c++ - Emplacing a std::pair -
is there way of emplacing std::pair
?
std::unordered_map<int, std::pair<std::string, std::string>> my_map; my_map.emplace(1, "foo", "bar"); // error
of course inserting possible:
my_map[2] = std::make_pair("bar", "foo");
but doesn't require unnecessary copying/moving?
is there way of emplacing std::pair?
the arguments need suitable constructor of pair<int, pair<string,string>>
, map's value_type
:
my_map.emplace(1, std::make_pair("foo", "bar"));
but doesn't require unnecessary copying/moving?
no; make_pair
makes pair of pointers string literals, used initialise (in case of emplace
) or assigned (in case of []
) strings contained in map.
Comments
Post a Comment