digitalmars.D - Optional parameters referring to previous parameters?
- Mehrdad (7/7) May 09 2012 Is this possible/should it compile?
- Matt Peterson (5/12) May 09 2012 Have you tried it?
- Mehrdad (5/19) May 09 2012 Well I mean of course I tried it (and it didn't work), but I was
- Mehrdad (1/1) May 09 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8075
- Steven Schveighoffer (8/14) May 10 2012 I *love* this idea.
- Mehrdad (5/12) May 10 2012 :D
- Mafi (7/13) May 10 2012 Solution:
- Mehrdad (3/19) May 10 2012 Yes! That's, like, 80 fewer characters... And it doesn't scale
- Steven Schveighoffer (4/19) May 10 2012 The same could be said for current default arg feature. If it's worth i...
- Steven Schveighoffer (5/27) May 10 2012 And BTW, it's not just sugar -- you are saving a function call and
- Tove (8/13) May 10 2012 ui, pretty please! I love it too, it would allow this marvelous
- dennis luehring (9/13) May 10 2012 and whats the difference to?
- Tove (6/19) May 10 2012 When used in the parameter list, the alloca() is injected into
- dennis luehring (2/7) May 10 2012 ah i see clearly now!
- Mehrdad (2/17) May 10 2012 lol, that's exactly why I asked for this..
- Simen Kjaeraas (2/16) May 11 2012 I loves that.
- Mafi (2/15) May 11 2012 I see: that is an interesting use case!
- Andrej Mitrovic (9/16) May 10 2012 If this is implemented I'd also throw this in:
Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }
May 09 2012
On Thursday, 10 May 2012 at 00:16:52 UTC, Mehrdad wrote:Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Have you tried it? I bet this isn't possible currently, but do open an enhancement request if it isn't. It's going to be a bit tricky to implement, but I like it.
May 09 2012
On Thursday, 10 May 2012 at 01:06:31 UTC, Matt Peterson wrote:On Thursday, 10 May 2012 at 00:16:52 UTC, Mehrdad wrote:Well I mean of course I tried it (and it didn't work), but I was just making sure I wasn't doing something wrong and that it wasn't recently added or something. Ok I'll make a request for it.Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Have you tried it? I bet this isn't possible currently, but do open an enhancement request if it isn't. It's going to be a bit tricky to implement, but I like it.
May 09 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8075
May 09 2012
On Wed, 09 May 2012 20:16:51 -0400, Mehrdad <wfunction hotmail.com> wrote:Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }I *love* this idea. Although, what happens if the expression for items is costly? We have to make sure if you do: process(someExpensiveCalculation()); it doesn't turn into: process(someExpensiveCalculation(), someExpensiveCalculation().length); -Steve
May 10 2012
On Thursday, 10 May 2012 at 11:54:42 UTC, Steven Schveighoffer wrote:I *love* this idea.:DAlthough, what happens if the expression for items is costly? We have to make sure if you do: process(someExpensiveCalculation()); it doesn't turn into: process(someExpensiveCalculation(), someExpensiveCalculation().length);It should be evaluated once anyway, since it might have side effects.
May 10 2012
Am 10.05.2012 02:16, schrieb Mehrdad:Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Solution: void process(R)(R items) { process(items, items.length); } void process(R)(R items, int maxCount); Is such a miminal syntactic sugar addition worth it?
May 10 2012
On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:Am 10.05.2012 02:16, schrieb Mehrdad:Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Solution: void process(R)(R items) { process(items, items.length); } void process(R)(R items, int maxCount); Is such a miminal syntactic sugar addition worth it?
May 10 2012
On Thursday, 10 May 2012 at 14:33:32 UTC, Mehrdad wrote:On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:er, more* charactersAm 10.05.2012 02:16, schrieb Mehrdad:Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me...
May 10 2012
On Thursday, 10 May 2012 at 14:33:32 UTC, Mehrdad wrote:On Thursday, 10 May 2012 at 14:11:32 UTC, Mafi wrote:er, more* charactersAm 10.05.2012 02:16, schrieb Mehrdad:Yes! That's, like, 80 fewer characters... And it doesn't scale with multiple optional arguments..Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me...
May 10 2012
On Thu, 10 May 2012 10:11:35 -0400, Mafi <mafi example.org> wrote:Am 10.05.2012 02:16, schrieb Mehrdad:The same could be said for current default arg feature. If it's worth it there, why not here? -SteveIs this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Solution: void process(R)(R items) { process(items, items.length); } void process(R)(R items, int maxCount); Is such a miminal syntactic sugar addition worth it?
May 10 2012
On Thu, 10 May 2012 11:48:25 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Thu, 10 May 2012 10:11:35 -0400, Mafi <mafi example.org> wrote:And BTW, it's not just sugar -- you are saving a function call and unnecessary code space. -SteveAm 10.05.2012 02:16, schrieb Mehrdad:The same could be said for current default arg feature. If it's worth it there, why not here?Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }Solution: void process(R)(R items) { process(items, items.length); } void process(R)(R items, int maxCount); Is such a miminal syntactic sugar addition worth it?
May 10 2012
On Thursday, 10 May 2012 at 15:51:08 UTC, Steven Schveighoffer wrote:On Thu, 10 May 2012 11:48:25 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote: And BTW, it's not just sugar -- you are saving a function call and unnecessary code space. -Steveui, pretty please! I love it too, it would allow this marvelous construct! auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }
May 10 2012
Am 10.05.2012 19:07, schrieb Tove:auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }and whats the difference to? auto my_extended_alloca(size_t size, void* buf) { return alloca(size); } except that you hide the alloca in the interface which can be easily overwritten with malloc or something? auto x = my_extended_alloca( 10, malloc(100) ); ???
May 10 2012
On Thursday, 10 May 2012 at 17:41:23 UTC, dennis luehring wrote:Am 10.05.2012 19:07, schrieb Tove:When used in the parameter list, the alloca() is injected into the parent scope. Your version doesn't work at all, as the allocation automatically ends with the scope of my_extended_alloca() instead of the scope of the caller!auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }and whats the difference to? auto my_extended_alloca(size_t size, void* buf) { return alloca(size); } except that you hide the alloca in the interface which can be easily overwritten with malloc or something? auto x = my_extended_alloca( 10, malloc(100) ); ???
May 10 2012
Am 10.05.2012 19:48, schrieb Tove:When used in the parameter list, the alloca() is injected into the parent scope. Your version doesn't work at all, as the allocation automatically ends with the scope of my_extended_alloca() instead of the scope of the caller!ah i see clearly now!
May 10 2012
On Thursday, 10 May 2012 at 17:07:49 UTC, Tove wrote:On Thursday, 10 May 2012 at 15:51:08 UTC, Steven Schveighoffer wrote:lol, that's exactly why I asked for this..On Thu, 10 May 2012 11:48:25 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote: And BTW, it's not just sugar -- you are saving a function call and unnecessary code space. -Steveui, pretty please! I love it too, it would allow this marvelous construct! auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }
May 10 2012
On Thu, 10 May 2012 19:07:47 +0200, Tove <tove fransson.se> wrote:On Thursday, 10 May 2012 at 15:51:08 UTC, Steven Schveighoffer wrote:I loves that.On Thu, 10 May 2012 11:48:25 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote: And BTW, it's not just sugar -- you are saving a function call and unnecessary code space. -Steveui, pretty please! I love it too, it would allow this marvelous construct! auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }
May 11 2012
Am 10.05.2012 19:07, schrieb Tove:On Thursday, 10 May 2012 at 15:51:08 UTC, Steven Schveighoffer wrote:I see: that is an interesting use case!On Thu, 10 May 2012 11:48:25 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote: And BTW, it's not just sugar -- you are saving a function call and unnecessary code space. -Steveui, pretty please! I love it too, it would allow this marvelous construct! auto my_extended_alloca(size_t size, void* buf=alloca(size)) { return buf; }
May 11 2012
On 5/10/12, Mehrdad <wfunction hotmail.com> wrote:Is this possible/should it compile? If not, should I make an enhancement request for it? It's been something that would've been useful in a ton of situations for me... void process(R)(R items, size_t maxCount = items.length) { }If this is implemented I'd also throw this in: struct Foo { property int x() { return 1; } void process(size_t y = x) { } } It doesn't have to be a property function, it could be a field. But it won't work right now unless "x" is marked static.
May 10 2012