preparing for const, final, and invariant
Derek Parnell
derek at nomail.afraid.org
Sun May 20 20:57:36 PDT 2007
On Sun, 20 May 2007 20:10:44 -0700, Walter Bright wrote:
> Regan Heath wrote:
>> Why not make this implicit 'in' parameter 'scope const final' avoiding the need to explicity say 'in' everywhere?
>
> It's a good idea, but then there needs to be some way to pass a mutable
> reference. Such as:
>
> class C { int x; }
> void foo(C c)
> {
> c.x = 3;
> }
>
> That doesn't work if 'const' is the default. Using out or inout doesn't
> work either, as those have slightly different semantics (an extra level
> of indirection).
What about 'const ref' meaning that a reference is being passed and that
reference is constant but not the data being referred to...?
class C { int x; }
void foo(const ref C c)
{
c.x = 3; // okay
c = new C; // fail
}
I know I wouldn't mind changing my code to do this. It is just a lot safer
and I'd rather "get it right" now than some years down the road with D.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
21/05/2007 1:53:21 PM
More information about the Digitalmars-d-announce
mailing list