Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a const qualifier from a variable in D

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.

like image 884
Charles L. Avatar asked Apr 19 '16 20:04

Charles L.


People also ask

Can you modify a const variable?

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).

What is const qualifiers?

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.

Can value of constant be changed?

Overview. A constant is a value that cannot be altered by the program during normal execution, i.e., the value is constant.

Why const in C?

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.


1 Answers

You might be interested in std.traits.Unqual.

Note that this gives the type with all qualifiers removed, not just const.

like image 150
rcorre Avatar answered Sep 27 '22 22:09

rcorre