Allow Conditional Compilation Inside Enum Declaration

Daniel N no at public.email
Thu Apr 4 07:39:36 UTC 2024


On Wednesday, 3 April 2024 at 17:57:31 UTC, Steven Schveighoffer 
wrote:
> Something like:
>
> ```d
> enum ??? foo {
>    case x;
>    case y;
>    case z;
>    // constructors?
>    this(int n) { this._value = cast(foo)n; }
>    // operators?
>    opBinary(...)
>    // static if works at a declaration scope!
>    static if(cond) {
>      case a;
>    }
> }
> ```
>
> The ??? is because I'm assuming it would be too ambiguous with 
> existing syntax. Maybe `enum struct`?
>
> But enums were basically copied from C (with duct-taped on 
> features), and other modern languages (such as swift) have 
> really considered how enums should be designed.
>
> -Steve

How about inheritance?

```d
enum A
{
   x,y,z,
}

static if(cond)
   enum B : A { w }
else
   alias B = A;
```



More information about the dip.ideas mailing list