How to work with an "arbitrary input range"?
Adam D. Ruppe
destructionator at gmail.com
Thu Oct 21 15:32:45 PDT 2010
I've seen the requirement tossed around a few times that functions should work
with arbitrary input ranges.
What, exactly, does this mean?
My first impression is:
void myFunction(T)(T t) if(isInputRange!(T)) {}
But I don't see how that actually works in practice. Suppose my function
parses some kind of text format, like D code or XML. It won't work with a
stream of integers.
OK, what about:
void myFunction(T)(T t) if(isSomeString!(T)) {}
The function could certainly work with that, but it doesn't seem to me to be
an arbitrary input range anymore; it is little different than if I just said
myFunction(string t).
Should it be something like this?
if(is(T.front : dchar))
(I'm sure that's actually wrong syntax, but hopefully you know what I mean)
That seems weak, since it wouldn't work with stdin.byLine, but perhaps it
shouldn't - the file format is char based, not line based. (should there be an
adapter range available there, to feed me one char at a time from a series of
lines? That seems to be adding a layer just to cancel out the one beneath it
though.)
Anyway, what's the right thing to do here?
More information about the Digitalmars-d
mailing list