Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are variadic arguments after a defaulted parameter well-formed?

template <typename... Args>
void bark( int = 0, Args&&... args ) {}

int main() {
     bark();
     bark(1);
     bark(1, 2);
}

Is this code well-formed according to the C++ Standard?

The proposed duplicate does not contain the same calls of the function.

like image 484
Puppy Avatar asked Feb 25 '16 22:02

Puppy


1 Answers

Due to CWG 777, the declaration is valid:

In a given function declaration, all each parameters subsequent to a parameter with a default argument shall have a default arguments supplied in this or a previous declarations or shall be a function parameter pack.

Deduction should succeed in all three cases, since the default argument makes no difference to the nature of deduction: If no argument to the pack parameter args is provided, it's deduced to the empty pack via [temp.arg.explicit]/3, otherwise the usual rule in [temp.deduct.call]/1 applies (as the pack is clearly not in a non-deduced context).

like image 151
Columbo Avatar answered Oct 21 '22 23:10

Columbo