Proposal for SentinelInputRange
deadalnix
deadalnix at gmail.com
Thu Feb 28 22:33:39 PST 2013
On Friday, 1 March 2013 at 06:19:19 UTC, Chris Nicholson-Sauls
wrote:
> A use case that comes immediately to mind: a sentinal range
> that, yes wraps, an infinite (but predictable!) range,
> effectively allowing you to take a head-slice of the infinite
> range.
>
> auto foo = infiniteRangeOfEvenNumbers();
> auto upto1000 = GenericSentinalInputRange!1000( foo );
>
struct GenericSentinelRange(R, Sentinel) {
R r;
@property auto front() {
return r.front;
}
void popFront() {
r.popFront();
}
@property empty() {
return r.front == Sentinel;
}
}
We don't need a new type of range at all. You confuse legitimate
uses case for using a sentinel to terminate a range and uses case
where an actual sentinel range is needed.
> So... I could live without a standard sentinal range concept
> (have so far, using sentinal injection with input ranges, which
> as Walter pointed out is really an incorrect use (abuse?) of
> input ranges), but I also know I'd be using it if it existed
> (and thereby cleaning up some code versus how I do it now).
You can live without, and guess what : if you use LDC (and
probably GDC) you'll get the performance boost Walter is talking
about.
More information about the Digitalmars-d
mailing list