C++ / Why Iterators Got It All Wrong
Robert M. Münch via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 2 13:22:44 PDT 2017
On 2017-09-01 20:34:32 +0000, Mark said:
> On Tuesday, 29 August 2017 at 12:50:08 UTC, Robert M. Münch wrote:
>> Maybe of interest: https://www.think-cell.com/en/career/talks/iterators/#1
>>
>> I haven't read everything, so not sure if it worth to take a look.
>
> Iterators have many problems. Andrei's talk some years ago, titled
> "Iterators Must Go", points out many of them in a clear fashion. I
> think most of the problems stem from the fact that they are inherently
> a leaky abstraction. Iterators basically treat all data structures as a
> singly/doubly linked list or as arrays (if they allow random access).
> There is no natural or intuitive way of describing, say, a tree or an
> arbitrary graph as a list/array. Ranges and cursors try to solve some
> of the issues but they still have this fundamental problem.
Iterators are not the silver bullet. But IIRC you can specify if you
want to iterate over a graph BF or DF. If you just need to "iterate"
over the elements things work pretty good IMO. If you want to select a
sub-set and then iterate things get much complicater anyway.
> It may be unrealisic to expect such a nice abstraction of iteration for
> other data structures, not to mention a universal one which will work
> for all interesting data structures.
That's true, hence I didn't ever expected this at all. Some pretty
simple & basic building blocks and the rest is done on-demand fitting
the use-case.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
More information about the Digitalmars-d
mailing list