Boost logo

Boost :

Subject: Re: [boost] [optional] operator<(optional<T>, T) -- is it wrong?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-11-27 17:48:19

On 28/11/2014 11:12, Marcel Raad wrote:
> I use it to represent "none" in statistics
> code similar to the example in the
> Boost.Optional documentation
> (
> /optional/doc/html/boost_optional/quick_st
> art/storage_in_containers.html).
> And I (perhaps mis-?)use it in
> configuration code to represent a default
> value so that I don't have to have an
> extra variable for each map:
> auto it = map.find(whatever);
> if(it != map.end()) return *it;
> else return map[boost::none];

Do either of those cases actually require the keys to be sorted? I'm
not sure about the former, but I doubt the latter does.

If sorting is not a requirement, you could use unordered_map instead. I
don't think anyone has an issue with std::hash being defined for
optional types.

Boost list run by bdawes at, gregod at, cpdaniel at, john at