Subject: Re: [boost] [variant] Please vote for behavior (Was: Basic rvalue and C++11 features seupport)
From: Louis Dionne (louis.dionne92_at_[hidden])
Date: 2013-01-21 11:55:37
> 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
My vote goes to II.
- Using moved-from objects should rarely happen, if ever.
- It is not even a breaking change since move from variants was not
supported in the past.
Moreover, I am explicitly against proposition III:
- The state of the moved-from variant is not explicitly set by the
programmer. I tend to prefer explicit to implicit.
- The type held in the moved-from variant depends on the types in the
variant, which could make it harder to use variants in generic code.
- It is simpler to have a single, well-documented behavior. It introduces
Would it be possible to assign to moved-from variant?
If so, proposition III is equivalent to proposition II with the following,
unless I am mistaken:
typedef variant<int, recursive_wrapper<foo> > V;
V v1(std::move(v2)); // using v2 now triggers an assertion
// (except when trying to set its content)
v2 = int(); // this is explicit and equivalent to III
Just my 2 cents.