August 27, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | On 8/27/13, <luis@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; } |
August 28, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Tuesday, 27 August 2013 at 21:21:31 UTC, Timon Gehr wrote: > - Safe alloca wrapper using the alloca default argument hack together with this. (i.e. bearophile's dynamically-sized strongly typed stack-based arrays.) > Oh Yes please! I've been waiting for this for a long time, there even was an enhancement request written to facilitate the alloca default argument hack! http://d.puremagic.com/issues/show_bug.cgi?id=8075 |
August 28, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2013-08-27 21:56, Walter Bright wrote: > No reason. It simply never occurred to anyone. I've never heard of > anyone wanting this in all my years of C, C++, and D. void foo (ubyte[] source, ubyte[] destination = source); Do some operation, by default override "source": void scale (int width, int height = width); > I'd reject an enhancement request for this unless someone could > demonstrate significant utility for it. So consistency is not a good argument? -- /Jacob Carlborg |
August 28, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 2013-08-27 23:51, Andrej Mitrovic wrote: > 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 agree, I've wanted this a couple of times. -- /Jacob Carlborg |
August 28, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Tuesday, 27 August 2013 at 21:51:48 UTC, Andrej Mitrovic wrote: > On 8/27/13, <luis@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)) { ... } |
August 28, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 8/28/2013 12:16 AM, Jacob Carlborg wrote: > On 2013-08-27 21:56, Walter Bright wrote: > >> No reason. It simply never occurred to anyone. I've never heard of >> anyone wanting this in all my years of C, C++, and D. > > void foo (ubyte[] source, ubyte[] destination = source); > > Do some operation, by default override "source": > > void scale (int width, int height = width); Is this really a problem that needs solving? >> I'd reject an enhancement request for this unless someone could >> demonstrate significant utility for it. > > So consistency is not a good argument? Is it really consistent if you have to add a new section in the documentation explaining it? |
August 29, 2013 Re: param2 = param1 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2013-08-28 23:51, Walter Bright wrote: > Is this really a problem that needs solving? It's not that important. You asked for use cases, I showed a couple. > Is it really consistent if you have to add a new section in the > documentation explaining it? That sounds like the documentation is not very well structured. Either this is missing from the documentation, and should be added, or it should already be documented somewhere. If it is already documented, and documented for templates, it should be moved to a section covering arguments both for templates and regular functions. So yes, possibly depending on how the documentation currently look like. BTW, if I recall correctly "consistency" is usually one of your arguments for doing, or not doing, something. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation