Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.98 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. typeid(T).name() alternative in c  11?
  2. template<typename T>
  3. class Vector {
  4.   void foo(int i) {
  5.     cout << __PRETTY_FUNCTION__ << endl;
  6.   }
  7. };
  8.        
  9. void Vector<double>::foo(int)
  10.        
  11. template<class T> struct meta {
  12.     static const std::string& get_name() {return T::class_name;}
  13. };
  14.        
  15. class MyClass {
  16. public:
  17.     static const std::string class_name("MyClass");
  18. };
  19.        
  20. template<> struct meta<int> {
  21.     static const std::string class_name("int");
  22.     static const std::string& get_name() {return class_name;}
  23. };
  24.        
  25. #define specialize_meta(name) template<>struct meta<name>{static const std::string class_name(#name); static const std::string& get_name() {return class_name;} };
  26. specialize_meta(double);
  27.        
  28. int main() {
  29.    std::cout << meta<int>::get_name();
  30. }
  31.        
  32. void foo(int) {} //function in question
  33. template<class T, T& a> struct metafunc; //dont define generic.
  34. template<decltype(foo), &foo> struct metafunc { //specialization
  35.     static const std::string func_name("void foo(int)");
  36. }