Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 12, 2011 inout and methods which return "this" | ||||
---|---|---|---|---|
| ||||
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?)
--
Best regards,
Vladimir mailto:vladimir@thecybershadow.net
|
September 12, 2011 Re: inout and methods which return "this" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On 09/12/2011 03:48 AM, Vladimir Panteleev 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?)
>
Yes, afaik inout is not functional at the moment.
|
September 12, 2011 Re: inout and methods which return "this" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Monday, September 12, 2011 05:38:36 Timon Gehr wrote: > Yes, afaik inout is not functional at the moment. http://d.puremagic.com/issues/show_bug.cgi?id=3748 - Jonathan M Davis |
September 12, 2011 Re: inout and methods which return "this" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On Sun, 11 Sep 2011 21:48:36 -0400, Vladimir Panteleev <vladimir@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
|
Copyright © 1999-2021 by the D Language Foundation