Boost logo

Boost :

Subject: Re: [boost] [optional] std::tr2::optional
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2011-11-19 12:26:25


> > * Use nullptr instead of boost::none? - this will make some uses of
> > optional pointers harder, but will make usage more clear in other
cases.
>
> I don't think nullptr is a good choice here because of the complications
you
> mentioned. Actually, I would prefer traditional clear() and empty()
methods
> for clearing and testing for value presence. The operator safe_bool() and
> operator!() may also be present in the interface for brevity in
conditional
> expressions.

Interesting. It looks like optional can be seen as a special container with
the maximum size of 1, and then functions like clear() or empty() come as
natural. On the other hand it can be seen as a pointer-like entity with
value semantics, and then functions like reset() and literal nullptr come
as natural.

I withdraw my suggestion to use nullptr. Function reset() would be a better
choice. I also find reset() preferable to clear() because reset can be
extended to accept parameters and the name does not become confusing;
similarly to unique_ptr::reset().

Also, if someone likes the assignment-of-"none" syntax, in C++11 there will
be a similar syntax available:

std::tr2::optional<T> op = {};
op = {};

Interestingly, boost::optional did have a reset function (now deprecated)
which was replaced with boost::none assignment. I wonder what was the
reason for this replacement.

Regards,
&rzej


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