www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



digitalmars.D - to const or not to const

↑ ↓ ← terranium <spam here.lot> writes:
class A
{
	private int[] Xrg;

	int[] rg() const
	{
		return Xrg;
	}
}

void f(invariant A a)
{
	a.rg[0]=0;
}
May 10 2008
↑ ↓ → terranium <spam here.lot> writes:
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?
May 10 2008