Douglas Gregor wrote:
I prefer to use any_cast<ValueType&>(x) to get a reference, since you state clearly your intention. Also, both static_cast and dynamic_cast uses that syntax.
That wouldn't change. The only difference is that the existing semantics return a copy of the ValueType when the type is correct, and throws bad_any_cast on failure. The signature is:
template<typename ValueType>
ValueType any_cast(const any & operand);
In many cases, it would be more useful to get an actual reference to the held value, so the folllowing signature(s) would be preferred:
template<typename ValueType> ValueType& any_cast(any & operand);
template<typename ValueType> const ValueType& any_cast(const any & operand);
If "operand" does not contain a value of type ValueType, any_cast throws bad_any_cast. Otherwise, it returns a reference to the held value. Why wouldn't we want this behavior?
I think that any_cast<ValueType>(x) shouldn't be equivalent to any_cast<ValueType&>(x), therefore any_cast<ValueType>(x) must have other semantics. It can return a copy or be illegal.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost