On Wed, Aug 01, 2007 at 03:12:20PM -0400, Richard Heck wrote:
> >>>>
> >>>Passing a std::map<docstring, docstring> by value seems wrong.
> >>>
> >>Yes. Made it const &. This required a const_cast, but that seems ok.
> >>
> >Not really.
> >
> It's necessary because I want to use operator[] on the map later, and
> that has no const version. That seems better than making it just &,
> without the const.
> >>+ KeyValMap & data2 = const_cast<KeyValMap &>(data);
> >>+ return data2[key];
> >>
> > return data.find(key)->second;
> >
> >Maybe even with ASSERETing on != data.end().
> >
> No, we don't want to do that. If the year field isn't given in a
> particular entry, say, then there won't be a year key in the map. But
> that's OK, and getValueForKey(data, "year") can just return docstring().
So 'find', no const cast and
some_iter it = data.find(key);
return it == data.end() ? docstring() : it->second;
Andre'