Isn't using find with retro awkward?

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 16 13:36:54 PST 2011


On Wednesday, February 16, 2011 13:00:13 Andrej Mitrovic wrote:
> On 2/16/11, jam <gr0v3er+d at gmail.com> wrote:
> > void main()
> > {
> > 
> >     auto a = [5,1,2,3,4,5,1];
> >     auto index = countUntil(retro(a),5);
> >     writeln(a[a.length-1-index .. a.length]);
> > 
> > }
> 
> That works for random-access ranges.
> But I was under the impression that bidirectional ranges don't
> necessarily have a length property?

I'm not sure. IIRC was assuming that they would and later someone pointed out a 
valid case where they wouldn't. So, in the long run, they probably won't but 
they may right now.

Actually, I'll check... No. They don't require a range. They must be a forward 
range and then have popBack and back in addition, but length is not required.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list