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
Most of the time you don't need a copy of the vector to be returned, a const reference will do just as well. You can always make a copy later if you need to.
Also you don't need to iterate through a map, they're optimized for searching with the find
method.
const vector & returnEdges(string key)
{
map >::iterator it = outgoing.find(key);
if (it == outgoing.end())
{
static vector empty_vector;
return empty_vector;
}
return it->second;
}