
Christian Mazakas wrote:
I'm with Andrey, I think the iterator API *is* the useful API. Typically, when I find something in a map, I'll either erase or do something else where reusing the iterator is a key part of everything.
My whole thing was about what users actually wanted vs all the costs of everything else.
What this user has always wanted is to not have to write this:
auto it = map.find( key );
if( it != map.end() )
{
// do something with it->second
}
That's why I'm always defining a helper function `lookup` that returns a
pointer, which allows me to write this instead:
if( auto p = lookup( map, key ) )
{
// do something with *p
}
If there's a built-in way to obtain an optional