Pergunta

I'm fully aware that the return value of std::type_info::name() is implementation-defined.

From the C++ standard (ISO/IEC 14882:2003 §18.5.1.7):

Returns: an implementation-defined NTBS.

My question is: why? Wouldn't this member function be much more useful if the standard dictated what the return value should be?

Foi útil?

Solução

Basically, if an implementation decides that they can't or doesn't want to support RTTI, they can just return "";. If the standard forced it to return something, they'd possibly kill any ability to have a compliant compiler for an environment where the resources for RTTI don't exist or want to be disabled (a microchip, for example.)

And let's not forget we don't want to force an ABI/name-mangling scheme on any compilers.

This follows the C++ philosophy "You don't pay for things you don't need."

Outras dicas

Where we're talking about vendors returning different strings, I think it's just a "we do it this way, you change" "no, we do it this way, YOU change" thing between the compiler vendors. Even the Standards committee doesn't want to annoy the compiler teams, and creating some neutral, new standard that isn't employed by any vendor tends to mean finding something that's nonsensical anyway.

Why aren't they all the obvious namespaces::class::functions etc. already? Some current implementations may have historically found it convenient to have it match the linker-required mangled names, been paranoid (or had paranoid clients) re memory usage etc..

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top