Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-10-17 14:51:56

On Wednesday 17 October 2001 03:39, you wrote:
> --- In boost_at_y..., Sebastien Marc <sebmarc_at_y...> wrote:
> > Yes steve, i understood that.
> >
> > What is not clear to me is that an exception is
> > thrown. I would have expected the convertion, the
> > actual cast from any, containing 5, to const char *)
> > to work.
> >
> > To me, the resulting string s should contain "5" but
> > instead the exception is thown.
> The boost::any class does not allow you to coerce the type stored
> into another type via any_cast<>. That's pretty appearant in the
> documentation, and I didn't see any place in the article that seemed
> to suggest otherwise. The sole purpose of any_cast<> is to cast a
> boost::any into the type of object that is stored within the
> boost::any object. If you store a const char* you can only
> any_cast<> to a const char*. Attempts to do otherwise result in
> either an exception or a null pointer return according to the rules
> given by Steve.

Fernando Cacciola's idea of using "peek" instead of "any_cast" might make
this more clear. The _cast implies a conversion of some sort, whereas "peek"
doesn't convey this notion of conversion.


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