libebml_ng
typeof.h
Go to the documentation of this file.
1 #ifndef TYPEOF
2 #define TYPEOF
3 #include <typeinfo>
4 #include <cxxabi.h>
5 #include <string>
6 #include <memory>
7 
8 namespace ebml {
9  template<typename T>
10  inline std::string typeof(const T* inst) {
11  int status;
12  std::unique_ptr<char, void(*)(void*)> name(
13  abi::__cxa_demangle(typeid(*inst).name(), nullptr, nullptr, &status),
14  std::free
15  );
16 
17  if (status != 0) {
18  return "Error getting type name";
19  }
20 
21  return name.get();
22  }
23 
24  template<typename T>
25  inline std::string typeof() {
26  int status;
27  std::unique_ptr<char, void(*)(void*)> name(
28  abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status),
29  std::free
30  );
31 
32  if (status != 0) {
33  return "Error getting type name";
34  }
35 
36  return name.get();
37  }
38 }
39 #endif
Definition: basictypes.h:40
std::string typeof(const T *inst)
Definition: typeof.h:10