param2 = param1

Yota yotaxp at thatGoogleMailThing.com
Wed Aug 28 09:52:51 PDT 2013


On Tuesday, 27 August 2013 at 21:51:48 UTC, Andrej Mitrovic wrote:
> On 8/27/13, <luis at luismarques.eu>"@puremagic.com 
> <"\"Luís".Marques"> wrote:
>>      // Not OK
>>      int foo(int x, int y = x)
>>      {
>>          return x*y;
>>      }
>
> Personally I think a much more useful feature would be (and this
> doesn't block this feature but it's related to default 
> arguments):
>
> struct S
> {
>     void foo(int x = this.y)
>     {
>     }
>
>     int y;
> }

I used to do something similar to that in another language.  
Something like...

void toggle(bool newState = !this.state) { this.state = newState; 
}

A function that could set state to a given value, or toggle it if 
omitted.  Then again, that language didn't have overloading at 
all.

Another example, but with more complex processing.
void speak(string msg, bool bypassMute = 
this.channel.isAdmin(this.username)) { ... }


More information about the Digitalmars-d mailing list