preparing for const, final, and invariant

Bill Baxter dnewsgroup at billbaxter.com
Sun May 20 21:56:04 PDT 2007


Walter Bright wrote:
> Derek Parnell wrote:
>> 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
>>  }
> 
> The trouble is that ref adds an extra level of indirection, and it would 
> be confusing to say that in this case it didn't.
> 
> Another option is to reuse 'inout' to mean 'mutable', since 'inout' is 
> replaced by 'ref'.

...which is what my last message was suggesting.  Any reason why that 
wouldn't work?   There is the question of what would happen to "out" and 
how you'd get out behavior applied to the pointer rather than the value.

And while "mutable" is on the table, is D going to have a story for 
private mutable members that don't affect the interface?  Like the 
classic private mutable cache member in C++.

--bb



More information about the Digitalmars-d-announce mailing list