fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <typeinfo>
  4.  
  5. #ifdef __GNUG__ // GCC
  6.  
  7. #include <cxxabi.h>
  8. #include <cstdlib>
  9.  
  10. static std::string readable_name( const char* mangled_name )
  11. {
  12. int status ;
  13. char* temp = __cxxabiv1::__cxa_demangle( mangled_name, nullptr, nullptr, &status ) ;
  14. if(temp)
  15. {
  16. std::string result(temp) ;
  17. std::free(temp) ;
  18. return result ;
  19. }
  20. else return mangled_name ;
  21. }
  22.  
  23. #else // not GCC
  24.  
  25. std::string readable_name( const char* mangled_name ) { return mangled_name ; }
  26.  
  27. #endif // __GNUG__
  28.  
  29. template < typename T > std::string type_to_string()
  30. { return readable_name( typeid(T).name() ) ; }
  31.  
  32. template < typename T > std::string type_to_string( const T& obj )
  33. { return readable_name( typeid(obj).name() ) ; }
  34.  
  35. #include <vector>
  36.  
  37. int main()
  38. {
  39. std::vector<std::string> seq ;
  40.  
  41. std::cout << type_to_string( 1234 ) << '\n'
  42. << type_to_string( std::realloc ) << '\n'
  43. << type_to_string( std::cout ) << '\n'
  44. << type_to_string( std::cin.rdbuf() ) << '\n'
  45. << type_to_string( *std::cin.rdbuf() ) << '\n'
  46. << type_to_string( std::string::npos ) << '\n'
  47. << type_to_string<std::string::iterator>() << '\n'
  48. << type_to_string( seq ) << '\n'
  49. << type_to_string( seq.size() ) << '\n'
  50. << type_to_string< decltype( std::srand(9) ) >() << '\n' ;
  51. }
  52.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
int
void* (void*, unsigned int)
std::ostream
std::basic_streambuf<char, std::char_traits<char> >*
__gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >
unsigned int
__gnu_cxx::__normal_iterator<char*, std::string>
std::vector<std::string, std::allocator<std::string> >
unsigned int
void