
30 Mar
2009
30 Mar
'09
2:37 a.m.
Hello, I have two vectors and want to random_shuffle them the same way using the zip_iterator. I thought the code below would do it, but when I execute it I see that both sequences get screwded up. What do I wrong? Best regards, andreas #include <vector> #include <boost/iterator/zip_iterator.hpp> #include <algorithm> #include <iostream> int main() { std::vector<int> I(8), J(8); for(int i = 0; i < I.size(); i++){ I[i] = J[i] = i; } std::random_shuffle(boost::make_zip_iterator(boost::make_tuple(I.begin(), J.begin())), boost::make_zip_iterator(boost::make_tuple(I.end(), J.end()))); for(int i = 0; i < I.size(); i++){ std::cout << I[i] << " " << J[i] << std::endl; } return 0; }