Date: Fri, 11 Jul 2025 13:18:16 -0400
On Fri, Jul 11, 2025 at 1:07 PM SD SH via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> 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.
I don't really understand what "compile-time variable" means.
Variables in functions executed at compile-time need not be constants.
So, are you asking for a variable which exists across translation
units that isn't a compile-time constant? Where compile-time code in
different translation units can read from and modify such variables?
How would that actually work? Like, somebody's got to read it first,
right? Somebody's got to write to it first. Who decides which TU gets
first dibs on the variable? Who decides which TU gets to access it
second?
This would be the Static Initialization Order Fiasco, but like way more.
Just look at your example: "count the number of instances of a
template in compile-time". So you have some variable that represents
that instance count. Is that variable somehow a constant expression?
Because if it is, then you should be able to do `array<T,
instance_count>`. Which is flat-out impossible for a compiler to do
because any TU could increase that count, and a TU's compiler cannot
reach out and look at every TU that could possibly be used with this
program.
So it's rather unclear what exactly it is that you're looking for.
<std-discussion_at_[hidden]> wrote:
>
> 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.
I don't really understand what "compile-time variable" means.
Variables in functions executed at compile-time need not be constants.
So, are you asking for a variable which exists across translation
units that isn't a compile-time constant? Where compile-time code in
different translation units can read from and modify such variables?
How would that actually work? Like, somebody's got to read it first,
right? Somebody's got to write to it first. Who decides which TU gets
first dibs on the variable? Who decides which TU gets to access it
second?
This would be the Static Initialization Order Fiasco, but like way more.
Just look at your example: "count the number of instances of a
template in compile-time". So you have some variable that represents
that instance count. Is that variable somehow a constant expression?
Because if it is, then you should be able to do `array<T,
instance_count>`. Which is flat-out impossible for a compiler to do
because any TU could increase that count, and a TU's compiler cannot
reach out and look at every TU that could possibly be used with this
program.
So it's rather unclear what exactly it is that you're looking for.
Received on 2025-07-11 17:18:29