简体   繁体   English

是否有可能在C ++中获取类型别名的名称?

[英]Is it possible to get the name of a type alias in C++?

In C++, is it possible to get the name of a type alias ? 在C ++中,是否可以获取类型别名的名称?

For instance: 例如:

using my_type = some_type<a,b,c>;
std::cout << get_type_name<my_type>() << std::endl;

Would print my_type , not some_type<a,b,c> . 会打印my_type ,而不是some_type<a,b,c>

No, you cannot, barring stringifying macros (which has nothing to do with type system). 不,你不能,禁止使用字符串化宏(与类型系统无关)。

There are ways to do strong typedefs, but they generate new types. 有很多方法可以执行强类型定义,但它们会生成新类型。

Note that the name on a typeid need not be human readable or even unique. 请注意,typeid上的名称不必是人类可读的,甚至是唯一的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM