lundi 2 mai 2016

Definition of "pattern" for parameter pack expansion

I understand that when an ellipsis (...) occurs to the right of a pattern containing a parameter pack, the pattern is expanded once for each parameter in the pack. However, though I have been able to find isolated examples of patterns with their expansion, I have been unable to find a definition of what constitutes a pattern. From what I can see, whitespace plays no role in the definition of the pattern, but parentheses do. For instance, in this example:

template<typename ... Ts>
void func(Ts)
{
    do_something(validate(Ts)...);
}

the do_something line would be expanded to:

    do_something(validate(var1), validate(var2), validate(var3))

if Ts happened to represent three variables. By contrast:

    do_something(validate(Ts...));

would be expanded to:

    do_something(validate(var1, var2, var3));

So clearly parentheses have something to do with determining where the pattern begins and ends. I can also see that whitespace does not. But that only gets me so far. I'd like to know exactly what constitutes a pattern, and how it will be expanded. I tried searching through the C++ Standard, but found too many instances of "parameter pack" to make that effective. Could someone please give me a definition of "pattern", or a link to a definition, or both?

Aucun commentaire:

Enregistrer un commentaire