#include <iostream>
#include <vector>
#include <boost/iterator/zip_iterator.hpp>
typedef boost::tuple<int&, float&> EntryTuple;
struct zip_func :
public std::unary_function<EntryTuple&, void>
{
void operator()(EntryTuple& t) const
{
std::cout << t.get<0>() << " " << t.get<1>() << std::endl;
}
};
int main()
{
const int N = 5;
std::vector<int> intVec(N,2);
std::vector<float> valueVec(N,5.5);
std::for_each(
boost::make_zip_iterator(
boost::make_tuple(intVec.begin(), valueVec.begin())
),
boost::make_zip_iterator(
boost::make_tuple(intVec.end(), valueVec.end())
),
zip_func()
);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKI2luY2x1ZGUgPGJvb3N0L2l0ZXJhdG9yL3ppcF9pdGVyYXRvci5ocHA+CgoKdHlwZWRlZiBib29zdDo6dHVwbGU8aW50JiwgZmxvYXQmPiBFbnRyeVR1cGxlOwoKc3RydWN0IHppcF9mdW5jIDoKICBwdWJsaWMgc3RkOjp1bmFyeV9mdW5jdGlvbjxFbnRyeVR1cGxlJiwgdm9pZD4KewogIHZvaWQgb3BlcmF0b3IoKShFbnRyeVR1cGxlJiB0KSBjb25zdAogIHsKICAgIHN0ZDo6Y291dCA8PCB0LmdldDwwPigpIDw8ICIgIiA8PCAgdC5nZXQ8MT4oKSA8PCBzdGQ6OmVuZGw7CiAgfQp9OwoKCmludCBtYWluKCkKewogIApjb25zdCBpbnQgTiA9IDU7CnN0ZDo6dmVjdG9yPGludD4gaW50VmVjKE4sMik7CnN0ZDo6dmVjdG9yPGZsb2F0PiB2YWx1ZVZlYyhOLDUuNSk7CgpzdGQ6OmZvcl9lYWNoKApib29zdDo6bWFrZV96aXBfaXRlcmF0b3IoCiAgYm9vc3Q6Om1ha2VfdHVwbGUoaW50VmVjLmJlZ2luKCksIHZhbHVlVmVjLmJlZ2luKCkpCiAgKSwKYm9vc3Q6Om1ha2VfemlwX2l0ZXJhdG9yKAogIGJvb3N0OjptYWtlX3R1cGxlKGludFZlYy5lbmQoKSwgdmFsdWVWZWMuZW5kKCkpCiAgKSwKemlwX2Z1bmMoKQopOwoKcmV0dXJuIDA7Cn0=
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&>&}'