C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: enabling default keyword for default method and function values
From: Vishal Oza (vickoza_at_[hidden])
Date: 2019-11-12 00:16:58


I think that named variables are confusing and could break existing code
the point is that I want to use the existing defaults in arbitrary
location without specifying the value. I am posting here to see if there is
interest in proposing it as a language feature.

On Nov 11, 2019 10:03 PM, "Andrew Tomazos" <andrewtomazos_at_[hidden]> wrote:

> +std-proposals
>
> I actually think it would be better to have named parameters. That way:
>
> auto fooval = foo(13, default, default, &foobazval);
>
> is instead:
>
> auto fooval = foo(bar: 13, foobaz: &foobazval);
>
> which I think reads a lot better. I suspect you only want this default
> feature so that you can default parameters in the middle of the list
> without defaulting those at the end.
>
>
> On Tue, Nov 12, 2019 at 3:00 AM Vishal Oza via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
>
>> I just wanted to know if the following idea is a bad idea. Should we
>> enable using the default keyword to function input value parameter if we
>> only care about one parameter that have default parameters both before and
>> after the parameter we care about?
>> For example:
>>
>> int foo(int bar = 3, int baz = 7, int* foobar = nullptr, int* foobaz =
>> nullptr) { ... }
>> ...
>>
>> int foobazval = 78;
>> auto fooval = foo(13, default, default, &foobazval); // = foo(13, 7,
>> nullptr, &foobazval)
>>
>>
>> The exceptions are references where there should never be a default value
>> and possibly type with no default this is only a possibly because the type
>> could be the same value as the type if the type was default constructed.
>> --
>> Std-Discussion mailing list
>> Std-Discussion_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups