Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-10-17 14:03:06

> It brings me with some of the problems i am facing
> with any. I tested some of the code in the article on
> my plateform (Linux gcc 2.95).
> boost::any a1 = 5;
> std::string s;
> s = boost::any_cast<const char*>(a1);
> The any_cast throws an exception. That's not supposed
> to happen from what you said in the article.

The *template* parameter doesn't determine whether or not any_cast will
throw; the *function* parameter does:

boost::any a = 5;
boost::any_cast<float>(a); // throws
boost::any * p = &a;
boost::any_cast<float *>(p); // doesn't throw (returns 0)

In this sense, any_cast usage is similar to (but not *exactly* like)

Base & b = ...;
dynamic_cast<Derived &>(b); // throws on error
Base * p;
dynamic_cast<Derived *>(p); // returns 0 on error


Boost list run by bdawes at, gregod at, cpdaniel at, john at