Subject: Re: [boost] [variant] Heads-up!
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2019-04-29 20:28:37
On Mon, Apr 29, 2019 at 4:23 PM Matt Calabrese <rivorus_at_[hidden]> wrote:
> On Mon, Apr 29, 2019 at 1:44 PM Steven Watanabe via Boost
> <boost_at_[hidden]> wrote:
> > AMDG
> > On 4/29/19 11:30 AM, Antony Polukhin via Boost wrote:
> > >
> > > I've merged a very cool optimization by Nikita Kniazev into the master
> > > branch. From now on boost::variant does pointer stealing for recursive
> > > variants.
> > >
> > > This significantly improves the performance of the variants move constructors.
> > >
> > > However if you use a variant variable after the std::move for anything
> > > except destruction and assignment then you're getting an UB. Beware!
> > >
> > boost::variant goes to great lengths to prevent
> > exactly this situation. You just broke it. This
> > change is unacceptable. Please revert it. This
> > optimization can be used iff. you have a way to
> > construct a valid object in the rhs.
> Stressing that, as Steven points out, this wouldn't violate the
> never-empty guarantee *if* after stealing you were able to
> default-construct something on the right-hand side and update the
> discriminator accordingly
Continuing on this thought, you don't necessarily have to
default-construct on the right-hand side to satisfy the never-empty
guarantee here. If the left-hand side also happens to currently
contain a recursive_wrapper, or something that is
nothrow-move-constructible, it can be moved into or swapped with rhs.
-- -Matt Calabrese
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk