Take an initializer_list instead of variadic arguments in the nextAre lambda function

This commit is contained in:
Username404 2021-09-18 15:32:31 +02:00
parent 01a1e5d339
commit fefa7b05c7
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 6 additions and 9 deletions

View File

@ -4,7 +4,6 @@
#include <string>
#include "ParseComponents.hpp"
#include "../Yerbacon.hpp"
#include <cstdarg>
#include <concepts>
namespace Parser {
@ -16,16 +15,14 @@ namespace Parser {
using namespace StandardComponents;
using enum tok::type;
unsigned int i = 0;
const auto nextAre = [&i, &lexed](convertible_to<unsigned int> auto nextValues,...) {
va_list argumentsList;
va_start(argumentsList, nextValues);
for (decltype(nextValues) j = 1; j <= nextValues; ++j) {
if (!cmp_greater(lexed.size() - i, nextValues) || lexed[i + j].toktype != va_arg(argumentsList, decltype(nextValues))) {
va_end(argumentsList);
const auto nextAre = [&i, &lexed]<convertible_to<unsigned int> T>(const initializer_list<T>& nextValues) {
unsigned int j = 1;
for (const T& nextValue: nextValues) {
if (!cmp_greater(lexed.size() - i, nextValues.size()) || lexed[i + j].toktype != nextValue) {
return false;
}
++j;
}
va_end(argumentsList);
return true;
};
for (;i < lexed.size(); ++i) {
@ -40,7 +37,7 @@ namespace Parser {
} else throw ParsingException((not next.toktext.empty()) ? '"' + next.toktext + "\" is not a valid class identifier" : "A class identifier is required", next.line);
} else {
if ((lexed.size() - i) > 2) {
bool isFinalDefine = nextAre(2, TAG, DEFINE);
bool isFinalDefine = nextAre({TAG, DEFINE});
if (isFinalDefine || next.toktype == DEFINE) {
parseTree << Define(isFinalDefine, current.toktext);
i += 1 + isFinalDefine;