Using 'with'

Vitaliy Fadeev vital.fadeev at gmail.com
Mon Jan 12 10:55:34 UTC 2026


Hi! Did we know you could do this?
To make the `enum` inside the `case` easier to read:

```D
void
func (Event* evt) {
     with (Event.Type)
     switch (evt.type) {
         case SET_E_PROP  : _set_e_prop (evt); break;
         case UPDATE_W    : _update_w   (evt); break;
         case UPDATE_H    : _update_h   (evt); break;
         case UPDATE_XY   : _update_xy  (evt); break;
         default:
     }
}

struct
Event {
union {
     Type type;

     enum
     Type {
         CLICK      =  1,
         UPDATE,
         SET_E_PROP,
         UPDATE_W,
         UPDATE_H,
         UPDATE_XY,
     }
}

```

Check the **with (Event.Type)**.



More information about the Digitalmars-d-learn mailing list