r/cpp • u/friedkeenan • Mar 08 '26
Exploring Mutable Consteval State in C++26
https://friedkeenan.github.io/posts/exploring-mutable-consteval-state/
83
Upvotes
r/cpp • u/friedkeenan • Mar 08 '26
View all comments
Show parent comment
4
u/_bstaletic Mar 08 '26 edited Mar 08 '26
At the risk of repeating myself, this is impressive.
Two things came to mind that
template for(constexpr mutable ...)could do, but this implementation can't:while(true)loop, as you've said yourself, but besides that it always iterates one step forward. There are cases where you might need to revisit a previous state. To be fair, at that point, it's not a loop, it's a state machine and is definitely out of scope of your experiment.I'm probably doing something wrong, but I can't find a way to do one thing in a loop if there's no state yet, and do a different thing if there is state.
if constexprand atry/catch. But all of that still ran into "uncaught exception".Speaking of exceptions, I see you're using clang-p3996 and throwing string literals. GCC implements
std::meta::exceptionand it's more useful than just a string.I don't know if it is a gcc bug, a not yet implemented feature or if I'm doing something wrong, but for the life of me I can't catch your exception...
Unrelated to the above, but
if(index <= 0)looks wrong...indexissize_t, so it can never be negative.EDIT: Oh... even without my changes, gcc fails to compile your code.
https://compiler-explorer.com/z/qY7zKKEvh
Untested, but you can also see lines 197 to 216, that could replace your
while(true)loop inexpand_loop()with ranges/views version. Not sure it's actually better.