Did you know; we need this operator!

Paul Backus snarwin at gmail.com
Sat Sep 14 01:01:06 UTC 2024


On Friday, 13 September 2024 at 18:49:06 UTC, Salih Dincer wrote:
> ```d
> alias DaysoftheWeekinEnglish D;
>
> void main()
> {
>   // with (Days)
>   auto days = [
>       "Pazar"     : D.Sunday,
>       "Pazartesi" : D.Monday,
>       "Salı"      : D.Tuesday,
>       "Çarşamba"  : D.Wednesday,
>       "Perşembe"  : D.Thursday,
>       "Cuma"      : D.Friday,
>       "Cumartesi" : D.Saturday
>   ];
>   assert(days["Cuma"] == DaysoftheWeekinEnglish.Friday);
>   assert(days["Pazar"] == D.Sunday);
> ```
>
> In this example, if you open the with() scope, everything works 
> inside the scope and the object is created correctly. However, 
> outside the scope, the object does not actually exist!

This could also be solved by allowing `with()` to be used as an 
expression, not just a statement:

```d
void main()
{
     auto days = with (Days) [
         "Pazar" : Sunday,
         // ...
     ];
}
```


More information about the Digitalmars-d mailing list