Since C++11 you can use std::multimap::emplace()
to get rid of one std::make_pair()
compared to harpun's answer:
std::multimap<std::pair<std::string, std::string>, std::vector<double>> mmList;
std::vector<double> test = { 1.1, 2.2, 3.3 };
mmList.emplace(std::make_pair("a", "b"), test);
The code above is no only shorter, but also more efficient, because it reduces the number of unnecessary calls of std::pair
constructors.
To further increase efficiency, you can use the piecewise_construct
constructor of std::pair
, which was introduced specifically for your use case:
mmList.emplace(std::piecewise_construct,
std::forward_as_tuple("a", "b"),
std::forward_as_tuple(test));
This code is no longer shorter, but has the effect that no unnecessary constructors are called. The objects are created directly in the std::multimap
from the given arguments.
Code on Ideone