Allow Conditional Compilation Inside Enum Declaration

Basile B. b2.temp at gmx.com
Tue Apr 2 17:10:07 UTC 2024


On Saturday, 30 March 2024 at 14:57:00 UTC, IchorDev wrote:
> To declare an enum type that may or may not have one or more 
> members depending on conditional compilation statements 
> requires duplicating the entire enum:
> ```d
> static if(cond){
> 	enum A{
> 		x,y,z,w,
> 	}
> }else{
> 	enum A{
> 		x,y,z,
> 	}
> }
> ```
>
> For an enum type with many members—or many conditionals—this 
> quickly becomes an insane amount of repetition.
>
> The logical solution is to just allow conditional compilation 
> statements inside enums:
> ```d
> enum A{
> 	x,y,z,
>     static if(cond){
> 		w,
> 	}
> }
> ```

I agree and the idea is not novel, [for example that], from 
memory it's been seen several times in the NG too. Risk for a DIP 
on this is that it could get rejected with a rationale such as 
"you can do that with metaprog, which is the D way". That is more 
or less what what Paul has replied, if you read under the lines.

[for example that]: https://issues.dlang.org/show_bug.cgi?id=9761


More information about the dip.ideas mailing list