DIPX: Enum Literals / Implicit Selector Expression

Dave P. dave287091 at gmail.com
Fri Dec 3 04:58:51 UTC 2021


On Friday, 3 December 2021 at 04:25:06 UTC, Elronnd wrote:
> On Friday, 3 December 2021 at 02:38:18 UTC, Dave P. wrote:
>> Where this really shines are with bit flags.
>
> Bitflags are a case where 'with' _does_ work.
>
> More generally, I'm sceptical of the feature for the reasons 
> Dennis and Paul mention; there is clearly some advantage wrt 
> boilerplate in some cases, but not for bitflags.

Except that `with` introduces a new scope and can’t be used at 
file scope:

```d
enum Flags {
     FOO = 1,
     BAR = 2,
     BAZ = 4,
     QUX = 8,
}

void main(){
     with(Flags){
         auto flags = FOO | BAR | BAZ | QUX;
     }
     // flags does not exist here.
}

with(Flags){ // Illegal
     auto f = FOO | BAR;
}
```

With is also very noisy syntactically when all you want is to use 
enums in a nicer way.


More information about the Digitalmars-d mailing list