C++ Logo

std-discussion

Advanced search

Compile-time Variables and Stateful Meta-programming / STMP

From: SD SH <Z5515zwy_at_[hidden]>
Date: Fri, 11 Jul 2025 17:07:10 +0000
The topic: Do we need compile-timevariables?

Now C++ has compile-time constants and functions so we can write compile-time code to compute values when compiling code and others, but doesn't approve mutable variables in compile-time.
Everybody knows that compile-time computing in C++ is functional and stateless then variable states is in opposition to the former.
In my opinion, stateful compile-time computing is neccessary, because C++ is a OO language, lots of things about types we couldn't do, like type registering, or just simply counting the number of instances of a template. We have many things to do based on that. And I saw some people used non-standard ways to implement some useful libraries (such as Boost.MSM).
As above, if we need to count the number of instances of a template in compile-time, we can simply use compile-time variables, and not use non-standard ways. Besides, we can implement lots of things we couldn't in the past, instead of putting them into standard. Now is 2025 but we couldn't use all of C++23 yet, so I think we need.

Himers

Received on 2025-07-11 17:07:14