Re: Passing Arguments on in Variadic Functions

2015-09-18 Thread jmh530 via Digitalmars-d-learn
On Friday, 18 September 2015 at 00:55:12 UTC, anonymous wrote: On Thursday 17 September 2015 23:27, jmh530 wrote: I think I could figure out how to look through the arguments for a bool, but wouldn't that make me give up the default value for the bool? If you don't find a bool, you use the d

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread anonymous via Digitalmars-d-learn
On Thursday 17 September 2015 23:27, jmh530 wrote: > I think I could figure out how to look through the arguments for > a bool, but wouldn't that make me give up the default value for > the bool? If you don't find a bool, you use the default value.

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 21:27:31 UTC, jmh530 wrote: There's probably a way to clean this up better, but this is what I was talking about. import std.algorithm : sum; import std.stdio : writeln; import std.traits : isNumeric; auto test(T)(T x, bool sample=true) { auto sum_

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 18:40:56 UTC, Adam D. Ruppe wrote: I would actually just make it required or do separate functions with it. Optional and variadics don't mix well together. (You could also loop through and look for a bool argument yourself but that is a bit messier.) It'

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Thursday, 17 September 2015 at 18:40:56 UTC, Adam D. Ruppe wrote: import std.meta; import std.traits; if(allSatisfy!(isNumeric, V)) should do it Was not aware of allSatisfy. Thanks.

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 17 September 2015 at 17:35:18 UTC, jmh530 wrote: I noticed that there's some interesting interplay with this technique and default arguments. Yeah, it expects the V... to consume the rest of the arguments so it doesn't really leave any room for the default arg. I would actually

Re: Passing Arguments on in Variadic Functions

2015-09-17 Thread jmh530 via Digitalmars-d-learn
On Monday, 14 September 2015 at 20:26:56 UTC, jmh530 wrote: Thanks to you both. This works perfect. I noticed that there's some interesting interplay with this technique and default arguments. From below, it is required that you put the ones with default arguments last. If there are only tw

Re: Passing Arguments on in Variadic Functions

2015-09-14 Thread jmh530 via Digitalmars-d-learn
Thanks to you both. This works perfect.

Re: Passing Arguments on in Variadic Functions

2015-09-14 Thread anonymous via Digitalmars-d-learn
On Monday 14 September 2015 21:59, jmh530 wrote: > This approach gives the correct result, but dmd won't deduce the > type of the template. So for instance, the second to the last > line of the unit test requires explicitly stating the types. I > may as well use the alternate version that doesn

Re: Passing Arguments on in Variadic Functions

2015-09-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 14 September 2015 at 19:59:18 UTC, jmh530 wrote: In R, it is easy to have some optional inputs labeled as ... and then pass all those optional inputs in to another function. I was trying to get something similar to work in a templated D function, but I couldn't quite get the same beh

Passing Arguments on in Variadic Functions

2015-09-14 Thread jmh530 via Digitalmars-d-learn
In R, it is easy to have some optional inputs labeled as ... and then pass all those optional inputs in to another function. I was trying to get something similar to work in a templated D function, but I couldn't quite get the same behavior. What I have below is what I was able to get working.