Allow Conditional Compilation Inside Enum Declaration
IchorDev
zxinsworld at gmail.com
Mon Apr 8 12:04:33 UTC 2024
On Wednesday, 3 April 2024 at 17:57:31 UTC, Steven Schveighoffer
wrote:
> I think what might be in order is to elevate enums to a more
> structured type (like Swift does).
>
> 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
Swift's `enum` is a tagged union. I'd love if we got tagged
unions, and the `enum struct` syntax isn't bad either. If D
tagged unions could functionally replace enums (i.e. if they
could have an arbitrary number of empty cases) then this would be
a fine replacement in my opinion. Sadly, no such feature exists
yet.
More information about the dip.ideas
mailing list