C++ Logo

std-proposals

Advanced search

default input value

From: Vishal Oza <vickoza_at_[hidden]>
Date: Tue, 12 Nov 2019 13:09:11 -0600
I would like to propose a new language feature into the language.

The feature is to allow writing default in function values to have default
value feed into the function/method as a part of the language.

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)

if the function have no default value calling default would be the same as
calling the default constructor. Errors would include assigning a default
value to a reference type and assigning default to a type with no
default constructor.

As a side note I have been told that as a extension allowing a to
specify function names could also solve the same problem but I do not want
to push for this hard as I think is can break code where the interface
definition does not match the implementation. This second approach would
allow C++ developer to only assign to field the the need in as order they
want like in the example bellow.

  auto fooval = foo( bar : 13, foobaz : &foobazval);

Received on 2019-11-12 13:11:46