Skip to content

Instantly share code, notes, and snippets.

@zmij
Last active June 23, 2016 14:48
Show Gist options
  • Save zmij/03da18f2defb90b51c8fd59187b974df to your computer and use it in GitHub Desktop.
Save zmij/03da18f2defb90b51c8fd59187b974df to your computer and use it in GitHub Desktop.
Demangle c++ name
#ifndef _UTIL_DEMANGLE_HPP_
#define _UTIL_DEMANGLE_HPP_
#include <cxxabi.h>
#include <string>
namespace util {
/**
* Usage:
* @code
* ::std::cout << demangle< ::std::iostream >() << "\n"
* @endcode
* @return Demangled type name
*/
template < typename T >
::std::string
demangle()
{
int status {0};
char* ret = abi::__cxa_demangle( typeid(T).name(), nullptr, nullptr, &status );
::std::string res{ret};
if (ret) free(ret);
return res;
}
} /* namespace util */
#endif /* _UTIL_DEMANGLE_HPP_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment