Last active
May 31, 2023 15:33
-
-
Save lambdaknight/b25df101ab738b210f8c47110ccd4403 to your computer and use it in GitHub Desktop.
[demangler] Simple function to print out a human readable name of a type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __LK_DEMANGLE_H__ | |
#define __LK_DEMANGLE_H__ | |
#if __has_include(<cxxabi.h>) | |
#include <cxxabi.h> | |
#include <cstdlib> | |
#include <memory> | |
#endif | |
#include <string> | |
template <typename T> | |
std::string demangle() | |
{ | |
#if __has_include(<cxxabi.h>) | |
int status = -1; | |
std::unique_ptr<char, void(*)(void*)> demangled_name | |
{ | |
abi::__cxa_demangle(typeid(std::remove_reference_t<T>).name(), NULL, NULL, &status), | |
std::free | |
}; | |
if(status == 0) | |
return demangled_name.get(); | |
else | |
return typeid(std::remove_reference_t<T>).name(); | |
#else | |
return typeid(std::remove_reference_t<T>).name(); | |
#endif | |
} | |
#endif //__LK_DEMANGLE_H__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment