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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With