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

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jun 16 11:28:53 UTC 2021


On Wednesday, 16 June 2021 at 11:08:52 UTC, Ola Fosheim Grøstad 
wrote:
> On Wednesday, 16 June 2021 at 10:53:26 UTC, Guillaume Piolat 
> wrote:
>> It's a healthy reminder of just how complicated everything is 
>> in C++, often for no good reason.
>
> That statement is true for some things, but not really in this 
> case. He focused on STL style table-pointers. Which is a 
> different concept.

Keep in mind that you don't have to implement the full "c++ 
iterator" in order to support ranged for-loops in modern C++. You 
only need to implement:

```
auto b = range.begin() // obtain progress state object
auto e = range.end()   // obtain end-marker

b != e  // comparable to D empty()
++b     // comparable to D popFront()
*b      // comparable to D front()
```

So it is basically not much more work to support ranged for in 
C++ than D, but most C++ library authors would implement full 
table-pointers and then it gets more time consuming.

For an application then there is no need to implement more than 
you need, obviously.






More information about the Digitalmars-d mailing list