How to get the data type of a std::any variable?

2.8k views Asked by At
std::any var = 1;

How can you get the type of var?

For example:

std::cout << GetTypeOf(var) << std::endl;

Output:

int
1

There are 1 answers

0
interjay On BEST ANSWER
std::cout << var.type().name() << std::endl;

Godbolt example

Note that the exact output of name() is implementation-defined, so you may get i instead of int for example.