Iterators and Ranges: Comparing C++ to D to Rust

jfondren julian.fondren at gmail.com
Mon Jun 14 14:10:48 UTC 2021


On Monday, 14 June 2021 at 13:45:14 UTC, Ola Fosheim Grøstad 
wrote:
> On Monday, 14 June 2021 at 13:30:52 UTC, Ali Çehreli wrote:
>> popFront() consumes the range, not the container:
>
> I glossed over the presentation, and I don't think he really
> covered things as well as he should.

Rust iterators have been discussed here before, e.g. in
https://forum.dlang.org/thread/arufovtvoewhyfuesvco@forum.dlang.org?page=1
and there are tones like "Rust has a better design and D does 
things
differently only for historical reasons.", and maybe "it'd be too 
hard
for D to emulate Rust without a borrow checker".

Similarly, I think people could agree that D's ranges are simpler 
than
than C++'s iterators, and that C++ just has iterators because they
hadn't though of ranges first.

What this presentation does well is to add nuance to these "X is 
just
better than Y" relationships. Some tasks are trivial for C++ but a
hassle for D, and surprisingly many tasks are excluded by Rust's
iterators. The only clear loser is Java, where there really are
historical reasons that hampered its design.

I'd also never noticed std.algorithm.cache until I went searching 
for
a library solution that I was sure must exist for the "filter 
calls
map's function twice" problem that D has, but Rust doesn't have.



More information about the Digitalmars-d mailing list