r/cpp • u/drop-volley • Sep 22 '26
Stateful compile-time functions
In section 9.1.2 of this book[1] it mentions that C++23 allows for stateful constexpr functions, and even shows an example. I can't seem to get it to compile on godbolt. Is the book completely wrong about something so fundamental, or am I doing something wrong?
[1] https://simplifycpp.org/books/cpp/Mastering_Modern_C++23_A_Complete_Guide_to_the_Latest_Standard.pdf
Edit: Godbolt link with code from that section -> https://godbolt.org/z/94j9EK87b
0
Upvotes
View all comments
1
u/ItsRSX Oct 05 '26
We used to have this before via not-managed for-MFC not-MFC mode MSVC __if_exists and other actually-somewhat-standard tricks to define monotonic counters. The biggest abuser of this being boosts typeof before decltype was a thing. iirc, herb sutter went out of his way to kill it everywhere possible around 2015. Good luck getting stateful machines with more than a few bits of entropy at compile time to actually work in <current year>