Douglas Gregor wrote: > > > The pointer cast returns NULL on failure, the value cast throws > > bad_any_cast. > > 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?
so, with the new scheme, if someone does a conversion to a pointer type and it fails, what happens? does it return Null or does it throw bad_any_cast? If the old functionality of returning Null on a bad pointer cast remains, and you simply can use either the pointer cast or the new reference cast, why not go with the new system? I have to imagine that a one-liner dereferencing a NULL pointer has to be a bit more dangerous than code that throws an exception. By the same token, if the user prefers a non-exception and intends to test the pointer, then so be it. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost