fork(3) 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<EntryTuple&, void>
  11. {
  12. void operator()(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. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.9/algorithm:62:0,
                 from /usr/include/boost/utility/swap.hpp:24,
                 from /usr/include/boost/tuple/detail/tuple_basic.hpp:40,
                 from /usr/include/boost/tuple/tuple.hpp:33,
                 from /usr/include/boost/iterator/zip_iterator.hpp:19,
                 from prog.cpp:4:
/usr/include/c++/4.9/bits/stl_algo.h: In instantiation of '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<float*, std::vector<float> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >; _Funct = zip_func]':
prog.cpp:34:1:   required from here
/usr/include/c++/4.9/bits/stl_algo.h:3755:14: error: no match for call to '(zip_func) (boost::iterator_facade<boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<float*, std::vector<float> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, boost::tuples::cons<int&, boost::tuples::cons<float&, boost::tuples::null_type> >, boost::random_access_traversal_tag, boost::tuples::cons<int&, boost::tuples::cons<float&, boost::tuples::null_type> >, int>::reference)'
  __f(*__first);
              ^
prog.cpp:9:8: note: candidate is:
 struct zip_func :
        ^
prog.cpp:12:8: note: void zip_func::operator()(EntryTuple&) const
   void operator()(EntryTuple& t) const
        ^
prog.cpp:12:8: note:   no known conversion for argument 1 from 'boost::iterator_facade<boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<float*, std::vector<float> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, boost::tuples::cons<int&, boost::tuples::cons<float&, boost::tuples::null_type> >, boost::random_access_traversal_tag, boost::tuples::cons<int&, boost::tuples::cons<float&, boost::tuples::null_type> >, int>::reference {aka boost::tuples::cons<int&, boost::tuples::cons<float&, boost::tuples::null_type> >}' to 'EntryTuple& {aka boost::tuples::tuple<int&, float&>&}'
stdout
Standard output is empty