Suppose I have a map that maps two strings into a long:
std::map<std::pair<std::string, std::string>, long> sums =
{
{{"1", "2"}, 3},
{{"3", "4"}, 7},
{{"5", "6"}, 11},
};
If I want to search in a map, it takes a std::pair<std::string, std::string>. If I receive the two strings to search by via different ways, I have to construct std::pair on the fly, which AFAIK copies the strings:
std::string one = "1";
std::string two = "2";
std::pair<std::string, std::string> myPair = std::make_pair(one, two);
std::map<std::pair<std::string, std::string>, long>::const_iterator it = sums.find(myPair);
If the map is searched A LOT, is there a way to not copy the strings to perform the search? There is no need to do a copy, it is required just by semantics of std::map.
EDIT: I am not attached to std::pair as key, it can be anything, even custom struct, as long as it is able to hold elements in the map by-value and search for them without a copy.