Did you know; we need this operator!
Salih Dincer
salihdb at hotmail.com
Fri Sep 13 18:49:06 UTC 2024
I have been looking at [this first draft by
Rikki](https://gist.github.com/rikkimax/33d8cac529c1f4e4ea94b2d4b53cfcb5) for a few days now. We have discussed it many times before:
* [First Draft: Member of
Operator](https://forum.dlang.org/post/xtmwtmkhmufpzeyrsxsb@forum.dlang.org)
* [Type Inference for Struct/Enum
Literals](https://forum.dlang.org/post/zbugncpaooowjsxldzue@forum.dlang.org)
* [The enum type inference problem is easily solved with
identifier
types](https://forum.dlang.org/post/tvnnoujdmaedgertbdes@forum.dlang.org)
Finally we have this. Because it is the best way to solve the
example below!
```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!
However, Rikki wrote that the proposed draft for this example
would not be a solution. However, with() looks nice but should be
used with caution.
SDB at 79
More information about the Digitalmars-d
mailing list