Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1
deadalnix
deadalnix at gmail.com
Wed Nov 23 14:21:23 UTC 2022
On Wednesday, 23 November 2022 at 13:41:12 UTC, ryuukk_ wrote:
> ```D
> // verbose API, readable
> struct SuperLongStruct
> {
> struct SuperLongInnerStruct
> {
> enum SuperLongEnum
> {
> VALUE_A, VALUE_B
> }
>
> SuperLongEnum super_long_flags;
> }
> SuperLongInnerStruct some_data;
> }
>
> // oh shoot
>
> SuperLongStruct super_long_struct = {
> some_data: {
> super_long_flags:
> SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A |
> SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A
> }
> };
>
> // oh nice!
>
> SuperLongStruct super_long_struct = {
> some_data: {
> super_long_flags: .VALUE_A | .VALUE_A
> }
> };
>
> ```
Try `alias E =
SuperLongStruct.SuperLongInnerStruct.SuperLongEnum;`
> ```D
> AttackType attack_type = .MELEE;
>
>
> (..)
>
>
> switch (attack_type)
> {
> case .MELEE:
> break;
> }
>
>
>
> ```
>
> now your variable name carry more and proper information about
> what it is,
```d
auto attack_type = AttackType.MELEE;
switch (attack_type) with(AttackType) {
case MELEE:
break;
}
```
More information about the Digitalmars-d
mailing list