
On Sun, Jun 22, 2008 at 07:22, Chris Ross
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)
This is the classic example of "why you didn't really want to use any
in the first place". If you're going to do anything with it (other
than pass it around), then you know something about its type, so any
more general than you really need. It's just like in unityped (aka
Dynamically Typed) languages.
Perhaps you can pass a boost::function