C++ Logo


Advanced search

Subject: Re: [std-proposals] Proposal: template function solution to Pythonic optional function arguments
From: Matthew Woehlke (mwoehlke.floss_at_[hidden])
Date: 2020-07-20 15:03:04

On 20/07/2020 15.06, Marcin Jaczewski via Std-Proposals wrote:
> pon., 20 lip 2020 o 20:23 codusnocturnus napisał(a):
>> Having the code-bloat associated with defining and naming a struct,
>> as well as pulling in std::optional all over the place to get the
>> equivalent of named parameters is objectively terrible (I think you
>> even questioned the viability), and, subjectively, it looks awful
>> at the call site, too.
> And both are needed, function arguments names do not exist in C++,
> this means you cannot overload on them, and to change this you will
> need split all C++ environment to old and new that support it and have
> different name mangling. Structs fix this as all needed functionality
> is already available to make it work.
> And for optional is not needed there, it could be replaced by current
> solution for optional parameters: predefined value:
> https://godbolt.org/z/h1Wb4K

We need a list of frequently requested features, because from what I can
tell, proper named arguments is number one on that list.

Personally, my thought has always been to make them opt-in:

   void foo(int x, int: y, int: z = 1, int: w = 0);

   foo(3, 4, .w: 1); // foo(3, 4, 1, 1)

Overloading and mangling seem to consistently turn into arguments, though.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups