If you want to return empty map if no element found you can do as simply as this:
Foo GetSubmap(std::string name)
{
FooContainer::const_iterator f = bar.find( name );
return f != bar.end() ? f->second : Foo();
}
Or you may throw exception in case no element found. You can also use bar[name]
, but you should know that it has side effect - empty Foo will be inserted into bar
each time you lookup for non existing element.