parameter pack to inputRange

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 5 23:09:29 PDT 2016


On Friday, 6 May 2016 at 06:08:24 UTC, Dicebot wrote:
> Unless parameter list is very (very!) long, I'd suggest to 
> simply copy it into a stack struct. Something like this:
>
> auto toInputRange (T...) (T args)
> {
>     struct Range
>     {
>         T args;
>         size_t index;
>
>         T[0] front () { return args[index]; }
>         void popFront () { ++index; }
>         bool empty () { return index >= args.length; }
>     }
>
>     return Range(args, 0);
> }

(note that you can actually make it random access range and not 
just input range, I simply have not defined required methods)


More information about the Digitalmars-d-learn mailing list