Advertisement
hazer_hazer

Varargs algo

Nov 19th, 2020
1,463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1.  
  2. if (arg_types.size() > other_arg_types.size() || arg_types.empty() && !other_arg_types.empty()) {
  3.             return false;
  4.         }
  5.  
  6.         size_t index = 0;
  7.         for (size_t arg_t_i = 0; arg_t_i < arg_types.size(); arg_t_i++) {
  8.             const auto & cur_t = arg_types.at(arg_t_i);
  9.             type_ptr vararg_t = cur_t->tag == TypeTag::VarargTag ? cur_t : nullptr;
  10.             if (vararg_t) {
  11.                 const auto & cmp_t = other_arg_types.at(index);
  12.                 while (index < other_arg_types.size() && vararg_t->compare(other_arg_types.at(index))) {
  13.                     index++;
  14.                 }
  15.                 // If next type after vararg is the same as vararg_t, go to previous type
  16.                 if (arg_t_i + 1 < arg_types.size()
  17.                 && vararg_t->compare(arg_types.at(arg_t_i + 1))) {
  18.                     index--;
  19.                 }
  20.             } else if (!cur_t->compare(other_arg_types.at(index))) {
  21.                 return false;
  22.             } else {
  23.                 // Go to next if not vararg and type was right
  24.                 index++;
  25.             }
  26.             // Go to next type for comparison
  27.             arg_t_i++;
  28.         }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement