It exists and works well:
std::map <int, std::string> x
{
std::make_pair (42, "foo"),
std::make_pair (3, "bar")
};
Remember that value type of a map is pair <const key_type, mapped_type>
, so you basically need a list of pairs with of the same or convertible types.
With unified initialization with std::pair, the code becomes even simpler
std::map <int, std::string> x {
{ 42, "foo" },
{ 3, "bar" }
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…