
2013/1/21 Andrey Semashev <andrey.semashev@gmail.com>:
On January 21, 2013 11:27:36 PM Sergey Cheban <s.cheban@drweb.com> 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