Why does std::any implementation use typeid?

456 views Asked by At

It seems that std::any works just fine in GCC and Clang even when compiling with -fno-rtti.

While looking at the libc++ source I see that they just use a simple trick:

they take the address of a variable templated on a type in any so that is how they get the unique id.

But this code is active only when there is no RTTI turned on.

That got me wondering. Why do they even use RTTI in the first place? Why not always use this solution? I have no idea why typeid would be faster than simple pointer (to a static variable that is instantiated per type) comparisons.

0

There are 0 answers