Boost logo

Boost Users :

Subject: [Boost-users] BOOST_FOREACH with Index
From: The Dude (thedsadude_at_[hidden])
Date: 2009-12-13 07:55:29


  Boost::foreach is very useful for iterating over a sequence and doing
something that depends only on the iterated element, e.g.,
BOOST_FOREACH(const Foo &f, foos)
  cout << << endl;

  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
BOOST_FOREACH(size_t i, const Foo &f, foos)
  cout << "The bar of element " << i << " is " << << endl;

  Is there an easy way to do so?

  Thanks & Bye,


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