Boost logo

Boost :

Subject: Re: [boost] [variant] Please vote for behavior (Was: Basic rvalue and C++11 features seupport)
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-01-21 10:19:08


2013/1/21 Antony Polukhin <antoshkka_at_[hidden]>

> Current implementation of recursive_wrapper move constructor is not
> optimal:
>
> recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
> : p_(new T(std::move(operand.get()) ))
> { }
>
> During descussion were made following proposals:
>
[...]

II: Set operand.p_ to NULL, add BOOST_ASSERT in get operations
>

I vote for II, because:

  + good performance
> + provides noexcept guarantee for move constructor
> + optimization will be used even if varinat has no type with trivial
> default constructor
> + easy to implement
>

And the above 4 points mean to me that it is a simple solution, which does
the job.

  - triggers an assert when user tries to reuse moved object
>

Yes, using the moved object in other cases then assigning something to it
is UB, so that's the right thing to do ;-)

  - adds an empty state to the recursive_wrapper

This empty state can only be achieved by moving from the object, right?
That's fine with me.

Regards,
Kris


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