DIP1044---"Enum Type Inference"---Formal Assessment

ryuukk_ ryuukk.dev at gmail.com
Wed Apr 26 14:58:21 UTC 2023


On Wednesday, 26 April 2023 at 11:52:31 UTC, Jacob Shtokolov 
wrote:
> On Tuesday, 25 April 2023 at 20:15:39 UTC, ryuukk_ wrote:
>> void set_connected()
>> {
>>     network_connect_state = NetworkConnectState.CONNECTED
>> }
>>
>> MySuperLongNameFlag flag = MySuperLongNameFlag.A | 
>> MySuperLongNameFlag.B | MySuperLongNameFlag.C | 
>> MySuperLongNameFlag.D;
>>
>>
>> set_flags(MySuperLongNameFlag.A | MySuperLongNameFlag.B | 
>> MySuperLongNameFlag.C | MySuperLongNameFlag.D)
>
> Okay, I understand this is sometimes really annoying, but in 
> this example, why can't you just:
>
> ```d
> import std.stdio;
>
> enum MySuperLongNameFlag : int
> {
>     A = 0b0001,
>     B = 0b0010,
>     C = 0b0100,
>     D = 0b1000,
> }
>
> void set_flags(MySuperLongNameFlag f) {}
>
> void main()
> {
>     with (MySuperLongNameFlag)
>     {
>         auto flag = A | B | C | D;
>         set_flags(A | B | C | D);
>
>         writefln("%04b", flag);
>     }
> }
>
> ```

No, what about this:

```d
  import std.stdio;

  enum MySuperLongNameFlag : int
  {
      A = 0b0001,
      B = 0b0010,
      C = 0b0100,
      D = 0b1000,
  }

  void set_flags(MySuperLongNameFlag f) {}

  void main()
  {
     MySuperLongNameFlag flag = A | B | C | D;
     set_flags(A | B | C | D);

     writefln("%04b", flag);
  }
```

No bloat, no extra indentation, no auto, you know what you are 
using


More information about the Digitalmars-d-announce mailing list