Range Construction Pattern

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


On Saturday, 22 February 2014 at 14:03:11 UTC, Philippe Sigaud 
wrote:
>> Now what remains is to retstrict create to only take a fun 
>> with *no*
> input arguments and a non-void return.
>>
>> How do I do that?
>
> With a template contraint.
> Not tested:
>
> import std.traits: isCallable, ParameterTypeTuple, ReturnType;
>
> auto create(alias fun)(size_t n)
> if (isCallable!fun && ParameterTypeTuple!(fun).length == 0
> && !is(ReturnType!fun == void))
> {
>     import std.range: iota, map;
>     return n.iota.map!(n => fun);
> }

Your solution with

    ParameterTypeTuple!(fun).length == 0

doesn't work here because currTime takes a defaulted argument.

I believe we need a new std.trait, say arityMin, for this.
Any ideas on how to implement that? Perhaps using 
__traits(compiles...?

See also my update at:
https://stackoverflow.com/questions/21954381/range-construction-pattern/21954416?noredirect=1#21954416


More information about the Digitalmars-d-learn mailing list