Boost logo

Boost :

Subject: Re: [boost] variant2 never empty guarantees (was: Re: Outcome/expected/etc/etc/etc)
From: Peter Dimov (lists_at_[hidden])
Date: 2017-06-14 16:06:18

Andrzej Krzemienski wrote:
> > This does not mean that all assignments are strong. In
> >
> > variant<vector<string>> v1, v2;
> >
> > v1 = v2;
> >
> > the assignment is basic, because that's the guarantee
> > vector<string>::operator= gives.
> Interesting. This satisfies the expectation that a number of people have
> expressed.

Exactly. For me basic is basic, regardless of whether the type stays the
same, but apparently this does not match people's intuitive expectations.

> But on the other hand, now that you are doing the double buffering
> anyway, making the assignment strong would come almost fo free.

Not free here because the above variant doesn't double-buffer (because all
alternatives are nothrow move constructible).

> If we continue the example with projections: if I change from the drop
> down menu from one mesh projection to another mesh projection, they are
> different projections, but can be encoded in the same type; maybe we
> should get the strong guarantee. If not in the assignment, then perhaps in
> a dedicated function.

You get the strong guarantee here in move assignment (because vector's move
assignment doesn't throw (... except for unequal allocators ...)):

    v1 = std::move(v2); // strong
    v1 = variant<vector<string>>(v2); // strong

    v1 = vector<string>{ "s1", "s2" }; // strong

and in emplace, because it doesn't use assignment:

    v1.emplace<vector<string>>( ... ); // strong too

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