C++ / Why Iterators Got It All Wrong

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 29 06:27:54 PDT 2017


On Tuesday, 29 August 2017 at 13:23:50 UTC, Steven Schveighoffer 
wrote:
>
> In Phobos, find gives you a range where the first element is 
> the one you searched for, and the last element is the end of 
> the original range. But what if you wanted all the data *up to* 
> the element instead? What if you just wanted to look at that 
> specific element? So we need several functions that do this, 
> and it's not always clear how to do it correctly, and it's 
> difficult to compose one function from the other. With 
> iterators, it's simple.
>
> -Steve

I was about to whine about exactly this, but thought it would be 
off topic ;)

I see "trim_left" in the slides which I'm guessing refers to what 
D calls "find". IMO, "trim_left" is a much better name. "find" 
should not return elements you didn't ask for, it should return a 
range of length 1 or 0.



More information about the Digitalmars-d mailing list