I have been looking at this first draft by Rikki for a few days now. We have discussed it many times before:
- First Draft: Member of Operator
- Type Inference for Struct/Enum Literals
- The enum type inference problem is easily solved with identifier types
Finally we have this. Because it is the best way to solve the example below!
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@79