fork(1) download
  1. #include<iostream>
  2. #include <string>
  3. #include <typeinfo>
  4. #include <cstdlib>
  5. #include <memory>
  6. #include <cxxabi.h>
  7. using namespace std;
  8.  
  9. std::string demangle(const char* name) {
  10. int status = -4; // some arbitrary value to eliminate the compiler warning
  11.  
  12. // enable c++11 by passing the flag -std=c++11 to g++
  13. std::unique_ptr<char, void(*)(void*)> res {
  14. abi::__cxa_demangle(name, NULL, NULL, &status),
  15. std::free
  16. };
  17. return (status==0) ? res.get() : name ;
  18. }
  19.  
  20. template <typename T> struct typename_struct {
  21. static std::string name() {
  22. std::string typeName = typeid(T).name();
  23. return demangle(typeName.c_str());
  24. }
  25. };
  26.  
  27. int main(){
  28.  
  29. cout << typename_struct<int****>::name();
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
int****