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 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 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-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)); }

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)); }

Re: template auto instantiation when parameters empty

2016-05-05 Thread Erik Smith via Digitalmars-d-learn
On Thursday, 5 May 2016 at 16:12:40 UTC, Steven Schveighoffer wrote: On 5/5/16 12:10 AM, Erik Smith wrote: I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource(null

template auto instantiation when parameters empty

2016-05-04 Thread Erik Smith via Digitalmars-d-learn
I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource(null);} this(string s) {} } auto resource = Resource.create; As a plain struct it works, but not as a templa

Re: what is equivalent to template template

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
You're close. An `alias` template parameter can be any symbol, including a template. But you can't pass in a template as a runtime parameter, so having `F f` in your parameters list is wrong (there's nothing to pass anyway; you already have the template, which is F). static void call(alias

Re: constructed variadic call

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
I don't think it's possible to call a vararg function whose number of arguments is only known at runtime, for the same reasons it is impossible in C [1]. Your switch statement is probably the best you can do, other than rewriting the API to not use varargs (which, depending on what the functi

what is equivalent to template template

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
C++ has template templates. I'm not sure how to achieve the same effect where (in example below) the template function myVariadic is passed to another function. void myVaridatic(A...)(A a) {} static void call(alias F,A...)(F f,A a) { f(a); } void f

Re: constructed variadic call

2016-05-03 Thread Erik Smith via Digitalmars-d-learn
On Monday, 2 May 2016 at 18:56:59 UTC, Stefan Koch wrote: On Monday, 2 May 2016 at 18:22:52 UTC, Erik Smith wrote: Is there way to construct an "argument pack" from a non-static array (like the switch below)? I need to transport a variadic call through a void*. switch (a.length) { case 1:

constructed variadic call

2016-05-02 Thread Erik Smith via Digitalmars-d-learn
Is there way to construct an "argument pack" from a non-static array (like the switch below)? I need to transport a variadic call through a void*. switch (a.length) { case 1: foo(a[1]); break; case 2: foo(a[1], a[2]); break; case 3: foo(a[1], a[2], a[3]); break; ... }

Re: inferred size for static array initialization

2016-05-02 Thread Erik Smith via Digitalmars-d-learn
I tried to combine the two solutions (Basile with the wrapper, Marco with the struct initializer support) but it didn't work. The struct initializer is not a array literal (seems obvious now). I might go with the 2nd but it's pretty heavy just to get the size. Thanks. struct S { int a

inferred size for static array initialization

2016-05-02 Thread Erik Smith via Digitalmars-d-learn
Is there a way to initialize a static array and have it's size inferred (and that works for arrays of structs using braced literals)? This would make it easier to maintain longer static array definitions. The code below doesn't work when removing the array size even though the array is declar