Range Construction Pattern

"Nordlöw" per.nordlow at gmail.com
Sat Feb 22 06:41:20 PST 2014


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


More information about the Digitalmars-d-learn mailing list