I want to create a non-const copy of a variable. I am doing this inside a templated function, which has an in ref
input, so the type (T
) has the const set. I see a ConstOf
function in https://dlang.org/phobos/std_traits.html but I cannot find an inverse so I can get a non-const type from T
.
Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration).
We use the const qualifier to declare a variable as constant. That means that we cannot change the value once the variable has been initialized. Using const has a very big benefit. For example, if you have a constant value of the value of PI, you wouldn't like any part of the program to modify that value.
Overview. A constant is a value that cannot be altered by the program during normal execution, i.e., the value is constant.
The const keyword allows a programmer to tell the compiler that a particular variable should not be modified after the initial assignment in its declaration.
You might be interested in
std.traits.Unqual
.
Note that this gives the type with all qualifiers removed, not just const
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With