Re: Are templates with variadic value parameters possible?

2016-07-15 Thread Mike Parker via Digitalmars-d-learn
On Friday, 15 July 2016 at 15:04:22 UTC, Devin Hill wrote: to the condition. It works pretty well! Granted, it doesn't allow for calling it in two ways like a variadic version would have: foo(1, 2, 3) // works with this setup foo([1, 2, 3]) // doesn't, but would only be occasionally

Re: Are templates with variadic value parameters possible?

2016-07-15 Thread Devin Hill via Digitalmars-d-learn
On Friday, 15 July 2016 at 05:23:15 UTC, Basile B. wrote: even better: template sameType(T...) { import std.meta; static if (!T.length) enum sameType = false; else enum sameType = NoDuplicates!T.length == 1; } Yeah, that's basically what I ended up doing, but

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:38:03 UTC, Basile B. wrote: two obvious: - recursive template. - staticIota in a foreach. (aliasSeqOf!(iota(1, T.length)) even better: template sameType(T...) { import std.meta; static if (!T.length) enum sameType = false; else enum

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:31:08 UTC, Devin Hill wrote: Thanks, that way of doing it does work. I guess that means there's no easy way to make sure all T are the same type without a template constraint? Yes, immediatly, now, I think that a contraint has to be used. But you have several

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Devin Hill via Digitalmars-d-learn
On Friday, 15 July 2016 at 04:08:19 UTC, Basile B. wrote: With D style variadics it works, you can build the array from the list and have a static array: = void foo(T...)(T t) { T[0][T.length] tt = [t]; // T[0] is the type writeln(tt); // [1,2,3] static

Re: Are templates with variadic value parameters possible?

2016-07-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 July 2016 at 03:43:49 UTC, Devin Hill wrote: Hi everyone, I have a struct template which takes an integer n, and then has a constructor taking that many arguments of type long, which looks like: struct Struct(int n) { this(long[n] nums...) { /* stuff */ } } This works and

Are templates with variadic value parameters possible?

2016-07-14 Thread Devin Hill via Digitalmars-d-learn
Hi everyone, I have a struct template which takes an integer n, and then has a constructor taking that many arguments of type long, which looks like: struct Struct(int n) { this(long[n] nums...) { /* stuff */ } } This works and lets me change n for each instantiation, but I wanted to