Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-04-22 05:02:11

Eric Niebler wrote:
> Daniel Wallin wrote:
>> xxx::for_each(cont, _1 += 2);
>> IMO C++ isn't missing a loop construct, it's missing a lambda construct.
> IMO, C++ is missing a foreach construct *and* a lambda construct. :-)
> When the loop body is non-trivial, writing it as a lambda would make the
> code hard to follow.

Why? I don't see why there should be much of a difference.

   foreach (x, v)


     lambda(x) { // or whatever a lambda syntax would look like

> I shudder at the thought of a lambda that takes up
> more than a few lines. A foreach construct would make it easier to read,
> in that case.

But then again, if we had a type inference mechanism and a range library
the for-loop is easy enough:

   for (auto r = range(v); r; ++r)

I would agree that there would be need for a simpler loop head if we had
to write every trivial loop on our own, but we have standard algorithms.

That said; there might be need for your macro right now, since we don't
have auto or lambda yet. :)

Daniel Wallin

Boost list run by bdawes at, gregod at, cpdaniel at, john at