News for hackers. Stuff that matters.
Re:We have C++14 by zak_mc_kracken on Monday August 18, 2014 @08:04PM (#8195367)
I've never understood the STL's infatuation with iterators. Why do I even need to know about them when all I want is walk through the collection?

Ideally, it should be something like:

    for (auto it : arr) {
      // do something with *it
    }
Re:We have C++14 by jeorgun on Monday August 18, 2014 @08:38PM (#8195472)
You can do that. That's part of C++11 and is supported by basically every major compiler.

The advantage of iterators is that they're incredibly flexible. You can use them for sub-ranges, reversed ranges, non-ranges like input and output iterators, etc, etc. This is vastly more powerful than something like, say, Objective C's NSFastEnumeration, which just allows for the trivial case handled by the range-based for-loop.

Re:We have C++14 by mpyne on Monday August 18, 2014 @08:47PM (#8195510)
> Why do I even need to know about them when all I want is walk through the collection?

Because there are algorithms where you may not want to walk through the whole collection. STL wasn't meant to be a container library alone, it also includes many generic algorithms that work using iterators to delimit the range of data to be operated upon.

Re:We have C++14 by jonstewart on Monday August 18, 2014 @08:28PM (#8195438)
It basically is this easy these days, thankfully. It is nice to have iterators, though, because it allows you some flexibility for swapping out the underlying data structures on existing algorithmic code. This has proved quite useful when I've written graph code.