Boost logo

Boost Users :

From: Chris Ross (cross+boost_at_[hidden])
Date: 2008-06-22 07:22:26


On Jun 21, 2008, at 12:22, Steven Watanabe wrote:
> Chris Ross wrote:
>> When I try to use boost::lexical_cast<int>(anyvar), I get compile
>> errors [...]
>> Can anyone else figure out why the above compile fails?
>
> any does not support streaming, which is required for lexical_cast.
>
> std::cout << is << std::endl;
>
> should give similar errors.

   Okay, that makes sense. Thank you for explaining why lexical_cast
isn't able to do what I hoped it would with my boost::any.

   Does anyone have a suggestion as to how I can get a value out of a
boost::any for which I don't know the specific type stored in it? A
subclass method is returning the boost::any, which is conceptually a
bool, but different subclasses may implement it as a bool, int,
int64_t, etc. I can just static-cast them to bool if I can get the
value out of the boost::any, but boost::any_cast gives a bad_any_cast
unless I cast it to exactly the right type (which as I noted, the
super-class doesn't know)

   Thanks. Any suggestions would be appreciated.

                     - Chris


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net