How to work with an "arbitrary input range"?

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 21 17:13:23 PDT 2010


On Thursday, October 21, 2010 15:32:45 Adam D. Ruppe wrote:
> 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.

Well, then it doesn't make sense for your function to take an arbitrary input 
range. What you need is an arbitrary input range of characters (which may or may 
not be strings since it could be an Array or an SList or some other type of 
container entirely). What you need to check for, therefore, is that T is an 
input range with the correct element type (which is essentially what Simen 
suggests doing).

- Jonathan M Davis


More information about the Digitalmars-d mailing list