Re: parameter pack to inputRange

2016-05-09 Thread Alex Parrill via Digitalmars-d-learn
On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: I like Alex Parrill's only() solution but it allocates a dynamic array as well by doing the equivalent of [args] in the guts of its implementation. No it does not. The constructor does `this.data = [values];`, but `this.data` is a fix

Re: parameter pack to inputRange

2016-05-09 Thread Dicebot via Digitalmars-d-learn
On Monday, 9 May 2016 at 12:36:00 UTC, Ali Çehreli wrote: On 05/09/2016 03:44 AM, Dicebot wrote: > Ali version generates a compile-time switch for index I think it's a run-time switch, generated by a compile-time foreach: E front() { final switch (index) {// <-- RUNTI

Re: parameter pack to inputRange

2016-05-09 Thread Ali Çehreli via Digitalmars-d-learn
On 05/09/2016 03:44 AM, Dicebot wrote: > Ali version generates a compile-time switch for index I think it's a run-time switch, generated by a compile-time foreach: E front() { final switch (index) {// <-- RUNTIME /* static */ foreach (i, arg; Args) { // <-- COMPI

Re: parameter pack to inputRange

2016-05-09 Thread Dicebot via Digitalmars-d-learn
On Sunday, 8 May 2016 at 23:48:01 UTC, Erik Smith wrote: Thanks! The static array version works for me too. It would be good to understand more about what is going on. It looks like the cost of the static array is an extra copy for each element. Maybe there is still a way to avoid that. T

Re: parameter pack to inputRange

2016-05-08 Thread Erik Smith via Digitalmars-d-learn
On Sunday, 8 May 2016 at 23:49:40 UTC, Ali Çehreli wrote: On 05/08/2016 04:48 PM, Erik Smith wrote: On Sunday, 8 May 2016 at 22:37:44 UTC, Dicebot wrote: On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: E front() { final switch (index) { /* static *

Re: parameter pack to inputRange

2016-05-08 Thread Ali Çehreli via Digitalmars-d-learn
On 05/08/2016 04:48 PM, Erik Smith wrote: On Sunday, 8 May 2016 at 22:37:44 UTC, Dicebot wrote: On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: E front() { final switch (index) { /* static */ foreach (i, arg; Args) { case i:

Re: parameter pack to inputRange

2016-05-08 Thread Erik Smith via Digitalmars-d-learn
On Sunday, 8 May 2016 at 22:37:44 UTC, Dicebot wrote: On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: E front() { final switch (index) { /* static */ foreach (i, arg; Args) { case i: return arg;

Re: parameter pack to inputRange

2016-05-08 Thread Dicebot via Digitalmars-d-learn
On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: E front() { final switch (index) { /* static */ foreach (i, arg; Args) { case i: return arg; } } } AFAIK, this will do fu

Re: parameter pack to inputRange

2016-05-08 Thread Dicebot via Digitalmars-d-learn
On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: On 05/05/2016 11:08 PM, Dicebot wrote: > Unless parameter list is very (very!) long, I'd suggest to simply copy > it into a stack struct. Something like this: > > auto toInputRange (T...) (T args) > { > struct Range > { >

Re: parameter pack to inputRange

2016-05-08 Thread Erik Smith via Digitalmars-d-learn
On Sunday, 8 May 2016 at 14:11:31 UTC, Ali Çehreli wrote: On 05/05/2016 11:08 PM, Dicebot wrote: > Unless parameter list is very (very!) long, I'd suggest to simply copy > it into a stack struct. Something like this: > > auto toInputRange (T...) (T args) > { > struct Range > { >

Re: parameter pack to inputRange

2016-05-08 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2016 11:08 PM, Dicebot wrote: > Unless parameter list is very (very!) long, I'd suggest to simply copy > it into a stack struct. Something like this: > > auto toInputRange (T...) (T args) > { > struct Range > { > T args; > size_t index; > > T[0] front

Re: parameter pack to inputRange

2016-05-06 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 6 May 2016 at 05:00:48 UTC, Erik Smith wrote: Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); } Use std.range.only: http://dlang.org/phobos/st

Re: parameter pack to inputRange

2016-05-05 Thread Dicebot via Digitalmars-d-learn
On Friday, 6 May 2016 at 06:08:24 UTC, Dicebot wrote: Unless parameter list is very (very!) long, I'd suggest to simply copy it into a stack struct. Something like this: auto toInputRange (T...) (T args) { struct Range { T args; size_t index; T[0] front () { ret

Re: parameter pack to inputRange

2016-05-05 Thread Dicebot via Digitalmars-d-learn
Unless parameter list is very (very!) long, I'd suggest to simply copy it into a stack struct. Something like this: auto toInputRange (T...) (T args) { struct Range { T args; size_t index; T[0] front () { return args[index]; } void popFront () { ++index;

Re: parameter pack to inputRange

2016-05-05 Thread Erik Smith via Digitalmars-d-learn
On Friday, 6 May 2016 at 05:20:50 UTC, Ali Çehreli wrote: On 05/05/2016 10:00 PM, Erik Smith wrote: Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); }

Re: parameter pack to inputRange

2016-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2016 10:00 PM, Erik Smith wrote: Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); } Inspired by my DConf 2016 talk ;) here is a fiber-based Inpu

Re: parameter pack to inputRange

2016-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 05/05/2016 10:00 PM, Erik Smith wrote: Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); } Just initialize an array with the arguments: void run(A...)

parameter pack to inputRange

2016-05-05 Thread Erik Smith via Digitalmars-d-learn
Is there an existing way to adapt a parameter pack to an input range? I would like to construct an array with it. Example: void run(A...) (A args) { Array!int a(toInputRange(args)); }