Reputation: 1573
Is there any way by which I can extract the type information of boost::any
type variable?
I tried to went through the source code of any
class and found a function giving some type information, but couldn't find a way to call it in my program.
Upvotes: 2
Views: 188
Reputation: 70273
It's right there in the examples for Boost.Any, no need to dig through the sources:
The following predicates follow on from the previous definitions and demonstrate the use of queries on any objects:
// ... bool is_int(const boost::any & operand) { return operand.type() == typeid(int); }
I.e., any::type()
gives you the typeid()
of the contained type.
Upvotes: 3