Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) BOOST_FOREACH

 

BOOST_FOREACH is a Boost macro to replace for-loops or to simplify their corresponding algorithm.

 

Examples

 

 

 

 

 

 

#include <boost/foreach.hpp>

//From http://www.richelbilderbeek.nl/CppTriple.htm
template <class Container>
void Triple(Container& c)
{
  BOOST_FOREACH(typename Container::value_type& i, c)
  {
    i*=3;
  }
}

#include <vector>
#include <cassert>

int main()
{
  std::vector<int> v;
  v.push_back(1);
  Triple(v);
  assert(v[0]==3);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict