0
std::any var = 1;

How can you get the type of var?

For example:

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

Output:

int
Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
anom
  • 41
  • 6

1 Answers1

0
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.

interjay
  • 107,303
  • 21
  • 270
  • 254