I have the following program where I make_zip_iterator on 2
vector<int>::iterator's and am trying to pass a Phoenix expression to
std::for_each on the iterator. I wrote a lazy version of tuple.get<N>
for that purpose. I get a compile error because the phoenix functor
only accepts references, whereas the tuple element seems to get passed
by value. What am I doing wrong?
Manjunath
#include <iostream>
#include <vector>
#include <algorithm>
#include
#include
#include
#include
#include
#include
#include
using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;
using namespace boost::phoenix::local_names;
using namespace std;
namespace fusion = boost::fusion;
struct print_tuple {
void operator()(const boost::tuple& t) const {
cout << t.get<0>() << " " << t.get<1>() << "\n";
}
};
struct get0_ {
template<typename Arg>
struct result {
typedef int type;
};
template<typename Arg>
int operator()(Arg a1) const {
return a1.get<0>();
}
};
function get0;
int main()
{
vector<int> a(10), b(10);
for(unsigned i=0, e=a.size(); i!=e; ++i) {
a[i] = i;
b[i] = i;
}
std::for_each(a.begin(), a.end(), cout << arg1);
std::for_each(boost::make_zip_iterator(boost::make_tuple(a.begin(),
b.begin())),
boost::make_zip_iterator(boost::make_tuple(a.end(),
b.end())), cout << get0(arg1));
}