inout type constructor applied to this-reference

Matthias Walter xammy at xammy.info
Fri Jan 10 02:04:50 PST 2014


Hi,

I read about inout functions in the language documentation which allows
to use inout in order to set the constness of the return type based on
the constness of some argument. What is not mentioned is that this also
works for the this-reference by marking the function itself inout:

So instead of

class C
{
  OtherClass foo;

  const(OtherClass) getOther() const { return foo; }
  OtherClass getOther() { return foo; }
}

we can write

class C
{
  OtherClass foo;

  inout(OtherClass) getOther() inout { return foo; }
}

Since the documentation only talks about marking arguments inout, can I
nevertheless rely on its behavior? Anyways, I think it is worth to be
included in the docs.

Best regards,

Matthias


More information about the Digitalmars-d-learn mailing list