3 ms·
> Think of constexpr evaluation as taking place "in the compiler’s imagination." This is a great line. constexpr and std::execution seem like neat ideas, mayb
by randusername 6mo ago
> Think of constexpr evaluation as taking place "in the compiler’s imagination."
This is a great line.
constexpr and std::execution seem like neat ideas, maybe I'll give them a shot if I build an AI harness around the compiler so it doesn't make me feel like a hopeless idiot for trying new things.
- tialaramex 6mo agoThe problem isn't so much that you feel like an idiot, at least at the time, but that you may think you're a genius and yet actually what you wrote was nonsense and the C++ compiler was under no obligation to tell you about that, indeed in many cases it's forbidden from doing so. The standard does require that if work was done at compile time the compiler is supposed to tell you if that was nonsense but (a) actually C++ is so complicated your compiler likely has many bugs in this respect and (b) you probably aren't sure the compiler did the work you expected at compile time, knowing all the excuses requires considerable expertise.
- Doxin 6mo agoI'd recommend you'd give D a try. It manages to have a bunch of the cool features C++ has, while still largely feeling like working in C with some of the cruft fixed. D's equivalent to "constexpr" is "compile time function evaluation". i.e. in any context where it only makes sense to run code at compile time, it will do so. This makes it trivial to do some pretty complex things at compile time. I put together an example that shows creating static arrays, dynamic arrays, and a dynamic array with a partial fibbonaci sequence all at compile time[0]. [0] https://gist.github.com/SuperDoxin/d9fcc68b73c035cbde7f0bd0826849e5 https://gist.github.com/SuperDoxin/d9fcc68b73c035cbde7f0bd08...