mardi 29 janvier 2019

Is base case function mandatory or could it be automatically synthesized?

In the following code :

void print()
{
    // This is our base case fn
    ;; // Do nothing
}

template <typename type1, typename... argspack>
void print(type1 a, argspack... args_rest)
{
    cout << a << ((sizeof...(args_rest) != 0) ? "," : "\n");
    print(args_rest...); // I guess this recursive call is inevitable
}

If the recursive call to variadic function is inevitable, the base case function is also inevitable. If so, is there a language feature, perhaps one that comes with modern c++, that help a programmer get away without writing a base case function?

Aucun commentaire:

Enregistrer un commentaire