Guest User

Untitled

a guest
May 5th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment