Range Construction Pattern

Philippe Sigaud philippe.sigaud at gmail.com
Sat Feb 22 06:02:59 PST 2014


> 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);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140222/90d98a59/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list