fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. #include <boost/iterator/zip_iterator.hpp>
  5.  
  6.  
  7. typedef boost::tuple<int&, float&> EntryTuple;
  8.  
  9. struct zip_func :
  10. public std::unary_function<const EntryTuple&, void>
  11. {
  12. void operator()(const EntryTuple& t) const
  13. {
  14. t.get<0>() = 10;
  15. std::cout << t.get<0>() << " " << t.get<1>() << std::endl;
  16. }
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22.  
  23. const int N = 5;
  24. std::vector<int> intVec(N,2);
  25. std::vector<float> valueVec(N,5.5);
  26.  
  27. std::for_each(
  28. boost::make_zip_iterator(
  29. boost::make_tuple(intVec.begin(), valueVec.begin())
  30. ),
  31. boost::make_zip_iterator(
  32. boost::make_tuple(intVec.end(), valueVec.end())
  33. ),
  34. zip_func()
  35. );
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
10 5.5
10 5.5
10 5.5
10 5.5
10 5.5