Boost logo

Boost :

Subject: Re: [boost] [variant] Basic rvalue and C++11 features support
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-13 14:33:00


Le 13/01/13 09:58, Antony Polukhin a écrit :
> 2013/1/6 Joel de Guzman <djowel_at_[hidden]>:
>> 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:
> ...
>
> I`ve finally got back from vacation, so let me add my 2 kopecks.
>
> We can make move constructor fast and noexcept (just like Joel
> proposed) and also guarantee non-empty behavior.
> The idea is to delay construction of object:
>
> T& get() {
> if (!get_pointer()) p_ = new T;
> return *get_pointer();
> }
>
> const T& get() const {
> if (!get_pointer()) p_ = new T; // mark p_ as mutable
> return *get_pointer();
> }
>
> So if move occurred object is empty, and if it is required again - it
> is default constructed.
>
> Any objections?
>
This would make less efficient the get operation. I would prefer to
force the boost::blank default construction.

Best,
Vicente


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