Expanding CTFE code during compilation
Steven Schveighoffer
schveiguy at gmail.com
Tue Jul 19 22:41:43 UTC 2022
On 7/19/22 5:43 PM, Azi Hassan wrote:
> Just in case this is a consequence of the XY problem, the reason why I'm
> looking for this is to make sure that the code I wrote did evaluate to
> what I'm expecting it to. Right now I do this with an enum assignment
> followed by static asserts, but I'd love it for there to be some sort of
> visual feedback.
>
> Thanks in advance
```d
template printEnum(alias x, string file = __FILE__, size_t line = __LINE__)
{
enum printEnum = x;
pragma(msg, file, "(", int(line), "): ", printEnum);
}
enum x = printEnum!(iota(1, 5).reduce!"a * b");
```
This will spit out the file, line, and value for the declaration.
Assuming this is useful for your double-checking you could do this, and
then switch it back when you have verified that it's correct.
-Steve
More information about the Digitalmars-d-learn
mailing list