inout and methods which return "this"

Steven Schveighoffer schveiguy at yahoo.com
Mon Sep 12 05:20:48 PDT 2011


On Sun, 11 Sep 2011 21:48:36 -0400, Vladimir Panteleev  
<vladimir at thecybershadow.net> wrote:

> What's the simplest const-correct way to write a method which returns  
> "this"?
>
> I tried the following to no avail:
>
> class Test
> {
> 	inout(Test) f() inout
> 	{
> 		return this;
> 	}
> }
>
> Result:
>
> test.d(3): Error: inout on return means inout must be on a parameter as  
> well for inout inout(Test)()
>
> It seems to me that the compiler could check the method's constness  
> along with that of its parameters, but doesn't (omission / unimplemented  
> feature?)

It's not correctly implemented.  When it is, the above will be correct.

-Steve


More information about the Digitalmars-d-learn mailing list