I know it is a very bad idea, so other suggestions on how to do it efficiently will be well-received.
Here\'s the thing. I have map
How about this:
std::vector find_by_key_maybe(const std::string & key)
{
std::map>::const_iterator it = themap.find(key);
return it == themap.end() ? std::vector() : it->second;
}
Or even, if themap
is non-const, and you also wish to add an empty vector into the map:
std::vector find_by_key_and_insert_if_missing(const std::string & key)
{
return themap[key];
}
It's perfectly OK to return a vector by value, if that's what the situation calls for.