Boost logo

Boost Users :

Subject: Re: [Boost-users] BOOST_FOREACH with Index
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-12-14 04:54:11

The Dude a écrit :

> However, I often need to iterate over a sequence and do some operation
> that depends on both the iterated element and the iteration index. E.g.,
> I would like something like
> <code>
> BOOST_FOREACH(size_t i, const Foo &f, foos)
> cout << "The bar of element " << i << " is " << << endl;
> </code>
> Is there an easy way to do so?

The index is not something generic enough.
What you would want in the general case is the iterator. But then, you
might as well use the real for loop, since BOOST_FOREACH_IT couldn't be
really less complicated.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at