Boost logo

Boost :

Subject: Re: [boost] [variant] Basic rvalue and C++11 features support
From: Mathieu Champlon (m.champlon_at_[hidden])
Date: 2013-01-06 13:04:03


On 06/01/2013 01:40, Joel de Guzman wrote:
> Hi,
>
> I just looked at the current state of variant and noticed that the
> implementation
> of recursive_variant's move ctor seems to be not as optimal as I
> hoped. The
> current implementation as written is:
>
> recursive_wrapper<T>::recursive_wrapper(recursive_wrapper&& operand)
> : p_(new T( detail::variant::move(operand.get()) ))
> {
> }
>
> Unless I am mistaken, I think the heap allocation is not needed
> and the target should simply grab the pointer and mark the source
> pointer as 0 (with additional checks for 0 in the dtor):
>
> (...)
>
> template <typename T>
> recursive_wrapper<T>::~recursive_wrapper()
> {
> if (p_)
> boost::checked_delete(p_); ,
> }
>

Hi,

Maybe I missed something but why would you test for p_ in the destructor ?
Isn't boost::checked_delete< T >( 0 ) valid ?

MAT.


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