fork(2) download
  1. //for testing
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. #include <string>
  6. #include <string>
  7. #include <cxxabi.h>
  8.  
  9. template<typename T>
  10. std::string type_name()
  11. {
  12. std::string tname = typeid(T).name();
  13. #if defined(__clang__) || defined(__GNUG__)
  14. int status;
  15. char *demangled_name = abi::__cxa_demangle(tname.c_str(), NULL, NULL, &status);
  16. if(status == 0)
  17. {
  18. tname = demangled_name;
  19. std::free(demangled_name);
  20. }
  21. #endif
  22. return tname;
  23. }
  24.  
  25. //just testing it
  26. struct MyStruct {};
  27.  
  28. int main()
  29. {
  30. std::cout<<type_name<int>()<<"\n"
  31. <<type_name<bool(MyStruct,MyStruct)>()<<"\n"
  32. <<type_name<std::vector<int>>();
  33. return 0;
  34. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
int
bool (MyStruct, MyStruct)
std::vector<int, std::allocator<int> >