digitalmars.D - behavior of this
- Ender KaShae (6/6) Jul 25 2007 I think that it would be nice to define how this behave for example:
- Jarrett Billingsley (17/21) Jul 25 2007 Const and invariant methods already exist, though not in the odd "static...
- Ender KaShae (2/6) Aug 02 2007 then perhaps my ref this could have similar syntax
I think that it would be nice to define how this behave for example: static func(ref this); would be called as a.func() which would be equivalent to class.func(a); i.e. this would be a reference to the reference that is calling the function. or static func(invarient this); would declare that the members of this are constant and can not be changed, if this was implemented then invarient instances of the class should only be able to call methods that have invarient this as a parameter i'm not sure if this will work but it would be very useful, especially for immutable types.
Jul 25 2007
"Ender KaShae" <astrothayne gmail.com> wrote in message news:f88h4u$31g2$1 digitalmars.com...static func(invarient this); would declare that the members of this are constant and can not be changed, if this was implemented then invarient instances of the class should only be able to call methods that have invarient this as a parameterConst and invariant methods already exist, though not in the odd "static with this as first parameter" way that you're proposing. class A { const int foo() { // Here I can only call other const/invariant methods // and can't modify the state of the object } invariant int bar() { // Similar but even stricter; can only call invariant // methods and access invariant fields } }
Jul 25 2007
Jarrett Billingsley Wrote:Const and invariant methods already exist, though not in the odd "static with this as first parameter" way that you're proposing.then perhaps my ref this could have similar syntax
Aug 02 2007