On Friday, 20 September 2013 at 10:02:58 UTC, Szymon Gatner wrote:
On Friday, 20 September 2013 at 10:00:32 UTC, Jacob Carlborg wrote:
On 2013-09-20 11:37, Szymon Gatner wrote:

If only std algorithms took containers (by that I mean things that container for accepts too) as arguments (and not iterators)... even in
the form of new functions like foreach_all, transform_all etc.

Can't a container be a range as well?

Not sure what you mean but C++ has no concept of a range. Apparent there is now a study group but atm standard algos are crippled compared to "container for".

To clarify what I mean by crippled: standard algorithms were
suppose to make code more expressive and one of the ways they
would do it was to eliminate tedious iterator-based for loops:

instead of

for (typename Contaniner<T>::const_iterator it = c.begin(), it !=
c.end() ++it) {..}

you could do:

std::for_each(c.begin(), c.end(), [](T&) {...};)

(of course this all only makes any sense with lambdas, without
them it is really hard to argue about expressivenes in the first
place)

but now we can do this:

for (auto& v : c) {}

which is even nicer than the for_each version. Algorithms do more
than iterating of course, but it is a shame they didn't evolve as
basic constructs.

Reply via email to