Syntax sugar for {} with structs

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jul 6 08:14:54 UTC 2022


On Saturday, 2 July 2022 at 16:37:55 UTC, Nick Treleaven wrote:
> On Saturday, 2 July 2022 at 16:15:13 UTC, Ola Fosheim Grøstad 
> wrote:
>>> ```d
>>> struct S{}
>>>
>>> void f();
>>> void f(S s);
>>>
>>> f({}); // which gets called?
>>> ```
>>
>> It is a parameter list for the constructor of S, so `F(S s)` 
>> gets called.
>
> So in D we would need a new type for a constructor parameter 
> list. We already have parameter lists which have a type, but we 
> can't use that because it would call `f()`, not `f(S)`.

So, you have to make a choice, the better choice is to not have 
implicit conversion and require a splat operator. The other 
choice is to make {...} unbound and let the use context bind the 
type. The third choice is to use f({{}}). The forth choice is to 
introduce proper tuples and type variables and let those 
represent parameter lists, which might be the best option.


More information about the Digitalmars-d mailing list