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