May 10, 2008 to const or not to const | ||||
|---|---|---|---|---|
| ||||
class A
{
private int[] Xrg;
int[] rg() const
{
return Xrg;
}
}
void f(invariant A a)
{
a.rg[0]=0;
}
| ||||
May 10, 2008 Re: to const or not to const | ||||
|---|---|---|---|---|
| ||||
Posted in reply to terranium | this example was born in thinking, how C# lives without const, this is closely connected with the nature of arrays. Strings in C# are immutable by the String class desing, but you can't take slices, if you want substring, you make it. Arays there are always mutable, and how do you really need an array slice? D strings are char arrays modified with language-level attribute, in .Net String is a mutable object with immutable content, and immutability is achieved through class-level implementation. Do we really need const for immutable strings and do we really need strings to be arrays? | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply