How to have optional argument of a function, being explicitly meant so with condition rule:
. if argument/parameter exists, it's as is supposed to be
. if it does not, the function does not outright have it, as if its declaration having the total number of argument substracted with 1, which means without that argument/parameter at all
without getting double function writing by overload fn.
it's at least 95 lines
@mbozzi, Default args are a little weird. As you know, they need to appear in the header file so that the compiler can fill in the value in the actual call with only the info in the header. I've noticed that the standard library seems to be removing default arguments in some places. I wonder what the reason for that is and what best practices have to say about it.
> How to have optional argument of a function, being explicitly meant so with condition rule:
> if argument/parameter exists, it's as is supposed to be
> if it does not, the function does not outright have it,
A fold-expression always starts with an open parenthesis and ends with a closing parenthesis;
the parentheses are an integral part of the fold-expression.
I've noticed that the standard library seems to be removing default arguments in some places. I wonder what the reason for that is and what best practices have to say about it.
I haven't noticed any such change, so I don't know. Do you have any specific example in mind?
@mbozzi, I've noticed it mostly in ctors. Here's a couple of examples:
On this page from cppreference for the basic_string ctor, form number 3 before C++17 has a default argument for count, but since C++17 it has two separate ctors.
On this page from cppreference for the basic_string ctor, form number 3 before C++17 has a default argument for count, but since C++17 it has two separate ctors.
Constructors for containers in the standard library come in pairs. Typically, one constructor takes an allocator argument and the other doesn't. In this case, one was missing. The new constructor allows std::string(str, pos, alloc)
instead of the equivalent, more verbose std::string(str, pos, std::string::npos, alloc).
On these pages for vector and list, form number 3 has a default argument for value which was removed in C++11.
For both vector and list, the addition of constructor 4 would cause ambiguity if the default arguments remained; there is a difference in semantics between the two overloads (in both cases, #4 doesn't make copies).
On this page for basic_istringstream, form number 2 has it's default argument removed for C++11.
basic_istringstream had an explicit default constructor (i.e., #2).
The change was proposed for C++11 by P0935: https://wg21.link/p0935 (grep that document for istringstream.)