Infinite BidirectionalRange?
Tomek Sowiński
just at ask.me
Sat Dec 25 05:04:17 PST 2010
Ali Çehreli <acehreli at yahoo.com> wrote:
> isRandomAccessRange at
>
>
> http://digitalmars.com/d/2.0/phobos/std_range.html#isRandomAccessRange
>
> describes what a RandomAccessRange is:
>
> <quote>
>
> A random-access range is a bidirectional range that also offers the
> primitive opIndex, OR an infinite forward range that offers opIndex.
> In either case, the range must either offer length or be infinite. The
> following code should compile for any random-access range.
>
> R r;
> static assert(isForwardRange!(R)); // range is forward
> static assert(isBidirectionalRange!(R) || isInfinite!(R));
> // range is bidirectional or
> infinite
> auto e = r[1]; // can index
>
> </quote>
>
> The part that starts with "In either case" does not make sense to me
> (and the sample code does not cover all possible cases). It seems to
> suggest that a RandomAccessRange may be an infinite
> BidirectionalRange.
>
> Since a BidirectionalRange defines both front() and back(), its being
> infinite can only come from asymptoting at one or more points in
> between the two ends. Is that useful?
>
> Does the document need correction or my understanding? :)
I think the docs silently assume bidir ranges can't be infinite. Then
again, infinity is defined as empty being false at compile-time, so
technically it's possible... I'm also curious what earthly mechanism
could be modeled by such a range.
--
Tomek
More information about the Digitalmars-d
mailing list