Subject: Re: [boost] [optional] std::tr2::optional
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-11-19 05:22:25
On 19.11.2011, at 00:16, Andrzej Krzemienski wrote:
>>> * Should exception safety guarantees for assignment operations be
>>> In boost::optional they only provide a basic guarantee.
>>> One option is to provide strong guarantee for types T which implement
>>> operator= with strong guarantee, and give basic guarantee for other
>>> Other option (not sure if it is possible) is to provide strong
>>> for all cases at the cost of run-time performance (heap allocation).
>> Provide the same exception guaranties as the T assignment seems the more
> My apologies, I wrote this in a hurry an didn't make myself clear. There
> are three cases to consider (leaving move assignment and no-throw copyable
> types aside):
> 1. Our stored type T provides a strong assignment - the choice is obvious:
> optional<T>'s assignment is also strong
> 2. T has "basic" assignment - the natural choice is to provide also a basic
> guarantee for optional<T>'s assignment.
> 3. T is neither copyable nor moveable -- it is like a scope guard, or
> boost::scoped_ptr. In this case optional<T> still provides assignment by
> making a "pseudo destructor call" followed by a call to placement new. --
> but this gives only basic guarantee.
> The question is if for this third variant we should be happy with only
> basic guarantee or to use a trick boost::variant is using with auxiliary
> heap-allocated object? (I do not even know if this is applicable though).
Do we even want the third variant? That is, do we want to support tr2::optional of something that is neither copyable nor movable?
My gut instinct says no, that's unintuitive.