LIPH's C++ Codes
demangle.h
Go to the documentation of this file.
1#ifndef LIPH_LANG_DEMANGLE_H_
2#define LIPH_LANG_DEMANGLE_H_
3
4#include <cxxabi.h>
5
6#include <string>
7#include <typeinfo>
8
9namespace liph {
10
11template <class T>
12std::string demangle() {
13 int status;
14 const char *s = typeid(T).name();
15 auto demangled = abi::__cxa_demangle(s, nullptr, nullptr, &status);
16 std::string ret = demangled ?: s;
17 free(demangled);
18 return ret;
19}
20
21template <class T>
22std::string demangle(const T& t) {
23 int status;
24 const char *s = typeid(t).name();
25 auto demangled = abi::__cxa_demangle(s, nullptr, nullptr, &status);
26 std::string ret = demangled ?: s;
27 free(demangled);
28 return ret;
29}
30
31} // namespace liph
32
33#endif // LIPH_LANG_DEMANGLE_H_
Definition: algorithm.h:10
std::string demangle()
Definition: demangle.h:12