Counting at compile-time

monkyyy crazymonkyyy at gmail.com
Sun Jan 26 20:10:20 UTC 2025


On Sunday, 26 January 2025 at 15:42:44 UTC, DLearner wrote:
> Suppose we have
>
> ```
> enum Count = 0;
>
> static if (<Compile-time evaluable cond-1>)
>    ...
>
>   enum Count = Count + 1; // is disallowed
> else
>
> static if (<Compile-time evaluable cond-2>)
>    ...
>
>   enum Count = Count + 1; // is disallowed
> else
>
> ```
>
> and the objective is to determine (at compile time) the number 
> of times cond-1 or cond-2 is triggered (perhaps for setting 
> size of a fixed array).
>
> So answer is zero, 1 or 2.
>
> But how to get that value into Count?

I have a compile time counter gist, it isnt no where near that 
clean and it testing the line between a compiler bug


More information about the Digitalmars-d-learn mailing list