Skip to content

Instantly share code, notes, and snippets.

@bwoods
Created July 8, 2015 23:55
Show Gist options
  • Save bwoods/bbc6bd26b73fa37e94ac to your computer and use it in GitHub Desktop.
Save bwoods/bbc6bd26b73fa37e94ac to your computer and use it in GitHub Desktop.
demangle C++ TypeID names (std::unique_ptr version)
#include <cxxabi.h> // gcc and clang…
#include <stdlib.h>
auto demangle(std::string&& name) -> std::unique_ptr<char, void(*)(char *)>
{
int status = 0;
return { abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), [] (char * p) { ::free(p); } };
}
#include <memory>
auto demangle(std::string&& name) -> std::unique_ptr<char, void(*)(char *)>;
template <typename T>
auto declname() { return demangle(typeid(std::declval<T>()).name()); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment