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.

Reply via email to