Boost logo

Boost :

Subject: Re: [boost] [optional] operator<(optional<T>, T) -- is it wrong?
From: Marcel Raad (raad_at_[hidden])
Date: 2014-11-27 17:12:51


Olaf van der Spek <ml <at> vdspek.org>
writes:

>
> On Thu, Nov 27, 2014 at 5:08 PM, Marcel
> Raad <raad <at> teamviewer.com> wrote:
> >> Has anyone reading this list every
> >> actually used
> >> std::map<boost::optional<T>, U>?
> >
> > Yes, I frequently use that.
>
> Could you describe how you're using it?

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];


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk