Expanding CTFE code during compilation
Azi Hassan
azi.hassan at live.fr
Tue Jul 19 21:43:01 UTC 2022
Hello,
Apologies in advance if this has been asked before. I can't find
the right words to express what I'm looking for, but essentially,
I'm wondering if the offers has the option of executing the parts
that can be evaluated at compile time and then replacing them
with the result of this evaluation. The C equivalent would be
compiling with the -E flag as explained here :
https://stackoverflow.com/questions/4900870/can-gcc-output-c-code-after-preprocessing
For example :
```
//main.d
import std;
void main()
{
enum x = iota(1, 5).reduce!"a * b";
x.writeln();
}
```
Then after running something like
```
dmd --expand-ctfe main.d -o expanded.d
cat expanded.d
```
We'd get :
```
//expanded.d
import std;
void main()
{
24.writeln();
}
```
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
More information about the Digitalmars-d-learn
mailing list