Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2003-01-22 13:13:44


On Wed, 22 Jan 2003, Jason House wrote:
> Douglas Gregor wrote:
> > 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?

It depends only on whether you pass any_cast a boost::any lvalue or a
boost::any pointer: in the former case, it will throw bad_any_cast and in
the latter case it will return a null pointer. So with a boost::any
variable 'x', the type of boost::any_cast<T*>(x) is T*& and the type of
boost::any_cast<T*>(&x) is T**.

        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk