fork(2) download
  1. #include <cxxabi.h>
  2. #include <typeinfo>
  3. #include <iostream>
  4. #include <string>
  5. #include <memory>
  6. #include <cstdlib>
  7.  
  8. std::string demangle(const char* mangled)
  9. {
  10. int status;
  11. std::unique_ptr<char[], void (*)(void*)> result(
  12. abi::__cxa_demangle(mangled, 0, 0, &status), std::free);
  13. return result.get() ? std::string(result.get()) : "error occurred";
  14. }
  15.  
  16. template<class T>
  17. void foo(T t) { std::cout << demangle(typeid(t).name()) << std::endl; }
  18.  
  19. int main() {
  20. foo("f"); //char const*
  21. foo(std::string()); //std::string
  22. }
  23.  
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
char const*
std::string