On Sunday, 23 June 2013 at 09:54:56 UTC, monarch_dodra wrote:
Isn't this what `until` does?

Not quite, it returns an object that returns those items when iterated on. But it is not the same type.

OK, I think we had a misunderstanding what "iterate" meant. I used it in the meaning "iterate the range at the time of the call" as opposed to "return a range that, when iterated, iterates its parameter".

The problem always boils down the fact that while we can get the same iteration scheme, it's never the same range type:

Range r = some_range;
r = r.until!"a == 5"; //Does not compile Until!Range and Range do not match r = r.take(5); //Does not compile: Take!Range and Range do not match

So is it all about reusing a variable?

For this, you can use the InputRange interface, and the InputRangeObject template which creates a crass type that inherits from the InputRange interface.

Of course, since what you are requesting is essentially runtime polymorphism, this will come with a performance cost of a virtual method call for every range primitive.

Reply via email to