Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[demangler] Simple function to print out a human readable name of a type.
#ifndef __LK_DEMANGLE_H__
#define __LK_DEMANGLE_H__
#if __has_include(<cxxabi.h>)
#include <cxxabi.h>
#include <memory>
#endif
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