wrong isInputRange design

pineapple via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 5 13:51:28 PST 2016


On Sunday, 4 December 2016 at 11:18:56 UTC, rumbu wrote:
> Yes, this is the same workaround I found, but that does not 
> solve the fact that the following code does not compile:

While it may be too late to redeem Phobos and its handling of 
arrays as ranges, it is worth noting that in the library I've 
been working on the `isRange` template behaves like you're 
expecting. In mach, `front` and `popFront` and `empty` are not 
defined for strings; rather, functions that accept ranges also 
accept types that ranges can be made to enumerate, including 
strings and other arrays.

If you really wanted an `isInputRange` that behaves like you're 
wanting, it's only a 6 line template that you would have to 
interject in your code.

     enum bool isInputRange(T) = is(typeof({
         T range = T.init;
         if(range.empty){}
         auto element = range.front;
         range.popFront();
     }));

https://github.com/pineapplemachine/mach.d



More information about the Digitalmars-d mailing list