Type Inference for Struct/Enum Literals

Nick Treleaven nick at geany.org
Mon Jul 8 10:45:22 UTC 2024


On Monday, 8 July 2024 at 07:02:34 UTC, ryuukk_ wrote:
> On Sunday, 7 July 2024 at 19:07:10 UTC, Nick Treleaven wrote:
>> On Saturday, 6 July 2024 at 08:04:36 UTC, ryuukk_ wrote:
>>> `MySelfExplanatoryType flag = MySelfExplanatoryType.A | 
>>> MySelfExplanatoryType.B MySelfExplanatoryType.C;`
>>
>> You could write:
>> ```d
>> auto flag = { with (MySelfExplanatoryType) return A | B | C; 
>> }();
>> ```
>
>
> No, this syntax is just bad, it's unreadable and over engineered

It's not great, but it does do what you said the point of the 
feature was:

> to avoid repetition and to make code more concise in places 
> that are relevant

I only suggest it for cases when using an alias is not acceptable.


More information about the dip.ideas mailing list