February 22, 2014 Re: Range Construction Pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw Attachments:
| per.nordlow: > > My try so far: > > import std.traits: isCallable, ReturnType, arity, ParameterTypeTuple; > > enum arityMin0(alias fun) = __traits(compiles, fun()); // new syntax in 2.064 > > auto repeat(alias fun)(size_t n) if (isCallable!fun && > arityMin0!fun && > > !is(ReturnType!fun == void)) > { > import std.range: iota, map; > return n.iota.map!(n => fun); > } For a nullary function, this solution is certainly OK: short and understandable. I found a way to parse an entire function param list, including default args, but I don't remember right now how I did that. Maybe by parsing 'fun.stringof' Maybe this exists in Phobos now? btw, I'd call this template 'apply', because repeat already exists in Phobos with a different use. |
February 22, 2014 Re: Range Construction Pattern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | > btw, I'd call this template 'apply', because repeat already exists in
> Phobos with a different use.
Good idea! I'll rename it.
I have a pile of extensions to std.algorithm, std.traits, std.numeric, I'll pull some day when I get the time...
/Per
|
Copyright © 1999-2021 by the D Language Foundation