Last active
June 23, 2016 14:48
-
-
Save zmij/03da18f2defb90b51c8fd59187b974df to your computer and use it in GitHub Desktop.
Demangle c++ name
This file contains 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 _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