QuantumC

Variadics

Back to home

Variadics are simple. They just mean any amount of arguments can be passed to this function.

int addMany(...args) {
    int sum = 0;
    while (!`is_empty(args)) {
        sum += `next(args, "int");
    }
    return sum;
}

...args declares a variadic argument (hence the … the … makes the argument variadic). `is_empty takes a variadic argument and returns if it has anything left to iterate over. `next takes a variadic argument and a stringified type and returns the next element casted to that type.