C++ Logo


Advanced search

[std-proposals] Implicitly accepting leading default function/template argument values

From: David Jones <davidjones1105_at_[hidden]>
Date: Sun, 6 Mar 2022 15:26:51 +0000
Consider the function

void foo(int i = 1, int j = 2, int k = 3);

Trailing default argument values can be accepted implicitly by simply skipping them in the function call:

foo(); //Accept default values for i, j, and k
foo(1); //Accept default values for j and k, supply value for i
foo(1,2); //Accept default value for k, supply values for i and j

But to my knowledge, there is no method for implicitly accepting leading default argument values - they must be copied out explicitly:

foo(1,2,5); //Accept default values for i and j by copying them out explicitly, supply value for k

I suggest that this could be done implicitly thus:

foo(,,2); //Accept default values for i and j, supply value for k
foo(,1); //Accept default values for i and k, supply value for j

This could also apply to default template arguments. For example, to specify a custom allocator for std::set the comparison type must currently also be explicitly specified :

std::set<int, std::less<int>, Myalloc>; //OK, but std::less<int> is superfluous.
std::set<int,, Myalloc>; //Currently an error

Thanks, David

Received on 2022-03-06 15:26:52