Am Fri, 17 Oct 2014 09:17:51 +0000 schrieb "ZombineDev" <[email protected]>:
> I saw [this][0] proposal for adding ranges to C++'s standard > library. The [paper][1] looks at D style ranges, but concludes: > > > Since iterators can implement D ranges, but D ranges cannot be > > used to implement iterators, we conclude that iterators form a > > more powerful and foundational basis. > > What do you guys think? > > [0]: https://isocpp.org/blog/2014/10/ranges > [1]: https://ericniebler.github.io/std/wg21/D4128.html True. Iterators are more foundational, ranges are more neat-o. ;) When you look at this C++ function as part of a signal processing home work you know why you don't want to see them in top level code: // C++ double mittelwert(const vector<double>& vektor) { vector<double>::const_iterator it; double summe = 0; for (it = vektor.begin(); it != vektor.end(); ++it) { summe += *it; } return summe / vektor.size(); } // D (removing iterators) double mittelwert(in double[] vektor) { double summe = 0; foreach (wert; vektor) { summe += wert; } return summe / vektor.length; } // D (using range sum function) double mittelwert(in double[] vektor) { return sum(vektor) / vektor.length; } -- Marco
