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
> (http://www.boost.org/doc/libs/master/libs
> /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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk