|
Boost : |
Subject: Re: [boost] [variant] Basic rvalue and C++11 features support
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-01-13 03:58:39
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?
-- Best regards, Antony Polukhin
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk