Boost logo

Boost :

Subject: Re: [boost] [variant] Please vote for behavior (Was: Basic rvalue and C++11 features seupport)
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-01-21 14:57:41


2013/1/21 Andrey Semashev <andrey.semashev_at_[hidden]>:
> On January 21, 2013 11:27:36 PM Sergey Cheban <s.cheban_at_[hidden]> wrote:
>>
>>
>> > II: Set operand.p_ to NULL, add BOOST_ASSERT in get operations
>> > + 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
>> > - triggers an assert when user tries to reuse moved object
>> > - adds an empty state to the recursive_wrapper
>> Let's think about non-recursive variants. For example:
>>
>> // both CFileObj and CDatabaseObj are movable, not copyable and
>> // not nothrow-default-constructible
>> boost::variant< CFileObj, CDatabaseObj > v1( CFileObj(SomeFileName) );
>> boost::variant< CFileObj, CDatabaseObj > v2( std::move( v1 ) );
>>
>> // What would be the state of v1 at this point?
>
>
> Moved-from CFileObj, I presume.

Correct, variant will contain CFileObj that was moved.

I've got some nice idea from discussion: nullable variant. If many
people use or want to use a variant with a type, that represents empty
state, we can create a separate nullable variant class. I think that
nullable variant can be implemented more efficient that the current
variant. For example we can simplify copy/move constructors and
assignment operators, guarantee fast noexcept default construction,
simplify metaprogamming and reduce compilation times. Maybe someone
want to implement it?

--
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