Skip to content

Instantly share code, notes, and snippets.

@lambdaknight
Last active May 31, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambdaknight/b25df101ab738b210f8c47110ccd4403 to your computer and use it in GitHub Desktop.
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.
#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