sv_jan5
sv_jan5

Reputation: 1573

Getting information about type contained in boost::any

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

Answers (1)

DevSolar
DevSolar

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

Related Questions