Guest User

Untitled

a guest
Feb 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. template<typename T, typename R, typename... Args>
  2. constexpr bool ckeck_method_type() {
  3.     char const* sig = __FUNCSIG__;
  4.     while (*sig++ != '<') {}
  5.     char const* f_type = sig;
  6.     int parens = 1;
  7.     while (*sig++ != ')') {}
  8.     sig++;
  9.     while (parens != 0) {
  10.         if (*sig == '(') {
  11.             parens++;
  12.         }
  13.         else if (*sig == ')') {
  14.             parens--;
  15.         }
  16.         sig++;
  17.     }
  18.     char const* t_args = sig + 1;
  19.     while (true) {
  20.         if (*f_type == '(') {
  21.             if (*t_args == ',' || *t_args == '>') {
  22.                 break;
  23.             }
  24.             return false;
  25.         }
  26.         if (*t_args == ',' || *t_args == '>') {
  27.             if (*f_type == '(') {
  28.                 break;
  29.             }
  30.             return false;
  31.         }
  32.         if (*t_args != *f_type) {
  33.             return false;
  34.         }
  35.         t_args++;
  36.         f_type++;
  37.     }
  38.     while (*f_type++ != ')') {}
  39.     f_type++;
  40.     if (f_type[0] == 'v' && f_type[1] == 'o' && f_type[2] == 'i' && f_type[3] == 'd' && f_type[4] == ')') {
  41.         if (t_args[0] == ',' && t_args[1] == '>') {
  42.             return true;
  43.         }
  44.         return false;
  45.     }
  46.     t_args++;
  47.     int deep = 1;
  48.     while (true) {
  49.         if (f_type[0] == 's' && f_type[1] == 't' && f_type[2] == 'r' && f_type[3] == 'u' && f_type[4] == 'c' && f_type[5] == 't' && f_type[6] == ' ') {
  50.             if (t_args[0] == 's' && t_args[1] == 't' && t_args[2] == 'r' && t_args[3] == 'u' && t_args[4] == 'c' && t_args[5] == 't') {
  51.                 f_type += 7;
  52.                 // msvc bug
  53.                 if (t_args[6] == ' ') {
  54.                     t_args += 7;
  55.                 }
  56.                 else {
  57.                     t_args += 6;
  58.                 }
  59.             }
  60.             else {
  61.                 return false;
  62.             }
  63.         }
  64.         if (f_type[0] == 'c' && f_type[1] == 'l' && f_type[2] == 'a' && f_type[3] == 's' && f_type[4] == 's' && f_type[5] == ' ') {
  65.             if (t_args[0] == 'c' && t_args[1] == 'l' && t_args[2] == 'a' && t_args[3] == 's' && t_args[4] == 's') {
  66.                 f_type += 6;
  67.                 // msvc bug
  68.                 if (t_args[5] == ' ') {
  69.                     t_args += 6;
  70.                 }
  71.                 else {
  72.                     t_args += 5;
  73.                 }
  74.             }
  75.             else {
  76.                 return false;
  77.             }
  78.         }
  79.         if (*f_type == '(') {
  80.             deep++;
  81.         }
  82.         else if (*f_type == ')') {
  83.             deep--;
  84.             if (deep == 0) {
  85.                 if (*t_args == '>') {
  86.                     return true;
  87.                 }
  88.                 return false;
  89.             }
  90.         }
  91.         if (*t_args != *f_type) {
  92.             if (f_type[0] == ' ' && ((f_type[1] == '&' && t_args[0] == '&') || (f_type[1] == '(' && t_args[0] == '('))) {
  93.                 deep += f_type[1] == '(';
  94.                 f_type++;
  95.             }
  96.             else {
  97.                 return false;
  98.             }
  99.         }
  100.         t_args++;
  101.         f_type++;
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment