int x = auto

John Colvin john.loughran.colvin at gmail.com
Wed Mar 22 20:31:47 UTC 2023


On Wednesday, 22 March 2023 at 17:58:38 UTC, Dom Disc wrote:
> On Wednesday, 22 March 2023 at 08:31:46 UTC, Ogi wrote:
>> Suggestion: allow implicit default-initialization using `type 
>> x = auto` syntax. This is the same as `type x = type.init` and 
>> `type x = type()`.
>>
>> This will be especially handy for functions with optional 
>> parameters.
>>
>> Before:
>> ```D
>> void fun(
>>         int x = 0,
>>         double y = double.nan,
>>         bool flag = false,
>>         string str = "",
>>         void* ptr = null,
>>         SomeStruct t = SomeStruct(),
>>         int[4] arr = [0, 0, 0, 0])
>> ```
>
> After:
> ```D
> void fun(
>    auto x = int.init,
>    auto y = double.init,
>    auto flag = bool.init,
>    auto str = string.init,
>    auto ptr = void*.init, // ok, not sure if this works
>    auto t = SomeStruct.init,
>    auto arr = int[4].init; // if this doesn't work, we should 
> fix it
> ```
>
> So, where is the problem?

No problem, if you submit a DIP and then go implement it in the 
compiler, because afaict that doesn’t work at all at the moment.


More information about the Digitalmars-d mailing list