Boost logo

Boost :

Subject: Re: [boost] Strong guarantee variant (Was: Outcome/expected/etc/etc/etc)
From: Peter Dimov (lists_at_[hidden])
Date: 2017-06-06 12:20:06


Niall Douglas wrote:
On 06/06/2017 12:14, Peter Dimov via Boost wrote:
> > I don't understand of what value is a guarantee that is strong when you
> > change type, but basic if you don't, but perhaps I'm missing something
> > here.
>
> My opinion would be that most users would expect a variant object to not
> be involved with the type being worked with, certainly not overriding its
> implementation. If the variant's state is pointing to type Foo, and I
> assign to the variant, it's 100% onto Foo's assignment operators what
> happens next, including any throwing or whatever guarantees.

That would mean the basic guarantee, for nearly all types in existence for
which the assignment can fail.

Types don't generally provide the strong guarantee on assignment as it
doesn't compose. If type T has strong assign, type U has strong assign,
struct { T t; U u; } no longer does. So it's more efficient to just do basic
everywhere, which does compose, and then at the specific point you want the
strong guarantee, use f.ex. the copy and swap trick to get it.

> 4. I do NOT want any additional runtime overhead whatsoever if all the
> variant's types have nothrow move constructors and nothrow destructors.

That's the easy case, but if you demand the same for N-1, things are more
convoluted. :-)


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