Boost logo

Boost :

Subject: Re: [boost] [optional] std::tr2::optional
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-11-21 13:36:20

On 21.11.2011, at 18:24, Andrzej Krzemienski wrote:

>>> 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.
>> Ok, I have no strong preference between reset() or clear() for making the
>> optional empty. However, a explicit empty() member would be useful
> anyway.
>> class MyClass
>> {
>> optional< int > m_x;
>> public:
>> bool has_x() const { return !m_x.empty(); }
>> };
>> I think, providing the reset() member with construction semantic is not a
> good
>> idea because it would make imposible in-place default construction. There
>> should be another method that would handle construction. In another post
> I
>> suggested assign() but I'm happy if someone comes up with a better name.
> I managed to come up with the following interface for initializing and
> un-initializing.
> My goal was also to not introduce in-place factories.

Initialize sounds slightly wrong.
I like the notion of optional as something like a single-element container, which would lead to the names emplace() for in-place construction, clear() for resetting to the none-state, and empty() as the test function. (Maybe with a positive filled() too.)


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