Type inference for default function / method arguments?

SealabJaster sealabjaster at gmail.com
Mon May 10 20:01:34 UTC 2021


On Monday, 10 May 2021 at 18:50:02 UTC, Witold Baryluk wrote:
> Hi,
>
> using D for very long time.

While not an exact solution, aliases can be a little useful here.

```d
import std.typecons : Flag;

// Shorten the names as much as you need of course.
alias Verbose = Flag!"verbose";
alias VeryVerbose = Flag"veryVerbose";

void func(Verbose verbose = Verbose.yes, VeryVerbose veryVerbose 
= VeryVerbose.no)
{
}
```

And you can of course do that for other types, e.g. `alias Opt = 
Options`

But again, this is more a workaround for why you're wanting the 
auto inference.


More information about the Digitalmars-d mailing list