1 | #ifndef C10_UTIL_TYPE_H_ |
2 | #define C10_UTIL_TYPE_H_ |
3 | |
4 | #include <cstddef> |
5 | #include <string> |
6 | #include <typeinfo> |
7 | |
8 | #include <c10/macros/Macros.h> |
9 | |
10 | namespace c10 { |
11 | |
12 | /// Utility to demangle a C++ symbol name. |
13 | C10_API std::string demangle(const char* name); |
14 | |
15 | /// Returns the printable name of the type. |
16 | template <typename T> |
17 | inline const char* demangle_type() { |
18 | #ifdef __GXX_RTTI |
19 | static const auto& name = *(new std::string(demangle(typeid(T).name()))); |
20 | return name.c_str(); |
21 | #else // __GXX_RTTI |
22 | return "(RTTI disabled, cannot show name)" ; |
23 | #endif // __GXX_RTTI |
24 | } |
25 | |
26 | } // namespace c10 |
27 | |
28 | #endif // C10_UTIL_TYPE_H_ |
29 | |