fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. #include <cstdlib>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <iterator>
  7. #include <utility>
  8.  
  9. #include <cxxabi.h>
  10.  
  11. std::string dem(const char* mang)
  12. {
  13. int status = -4; // some arbitrary value to eliminate the compiler warning
  14. std::string ret;
  15. char* d = abi::__cxa_demangle(mang, NULL, NULL, &status);
  16. if (status == 0 && d) ret = d;
  17. if (d) std::free(d);
  18. return (status == 0 ? ret : mang);
  19. }
  20.  
  21.  
  22. template <typename Ret, typename ... Args>
  23. void func (Ret (*f)(Args...))
  24. {
  25. std::cout << dem(typeid(f).name()) << std::endl;
  26. std::vector<std::string> types {dem(typeid(Args).name())...};
  27. std::copy(std::begin(types), std::end(types), std::ostream_iterator<std::string>(std::cout, "\n"));
  28. }
  29.  
  30. int foo (int a, int* b, double** c) {}
  31.  
  32. int main ()
  33. {
  34. func(foo);
  35. }
  36.  
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
int (*)(int, int*, double**)
int
int*
double**