mercredi 21 mars 2018

Return alias identificator instead of type in typeid(SOME_TYPE).name()

In the following example

template <typename T>
void foo() {
    const char* name = typeid(T).name();
    std::cout << name;
}

the variable 'name' will be initialized by type 'T' name. It is very convinient if we need to print this template type name. But, if we have the alias:

using shortTypeName = std::smth::smth_else::smth_more;

in the result of the call

foo<shortTypeName>();

will be printed 'std::smth::smth_else::smth_more'. And I need to print exactly the alias name, but not the type it is defined. Can somebody give an advice, how I can do this?

Aucun commentaire:

Enregistrer un commentaire