Type inference for default function / method arguments?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon May 10 20:58:43 UTC 2021


On Mon, May 10, 2021 at 06:50:02PM +0000, Witold Baryluk via Digitalmars-d wrote:
[...]
> Really, I would like to be able to say this:
> 
> ```d
> import std.typecons : Yes, No;
> 
> void show_help_and_exit(const string exec_name, const string extra_help,
>                         auto verbose = No.verbose,
>                         auto reallyverbose = No.reallyverbose,
>                         auto shorthelp = No.shorthelp) {
[...]

I've also felt the need for this. Since the default value already
implies the type, it seems to be a violation of DRY to have to type it
out, especially for enums where you already have to type the name of the
enum.

IMO, this deserves to be a DIP. It's useful, self-contained, and
probably quite easy to implement.


T

-- 
There are two ways to write error-free programs; only the third one works.


More information about the Digitalmars-d mailing list