1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <boost/iterator/zip_iterator.hpp>
#include <boost/range/as_array.hpp>
#include <algorithm>
#include <iostream>
struct first_element_compare
{
bool operator()(const boost::tuple<int, int>& lft, const boost::tuple<int, int>& rgt) const
{
return boost::get<0>(lft) < boost::get<0>(rgt);
}
};
int main()
{
int foo[] = {9, 5, 6, 1};
int bar[] = {1, 2, 3, 4};
std::sort(
boost::make_zip_iterator(
boost::make_tuple(
&foo[0],
&bar[0]
)
),
boost::make_zip_iterator(
boost::make_tuple(
foo + 4,
bar + 4
)
),
first_element_compare()
);
std::cout << boost::as_array(foo) << std::endl;
std::cout << boost::as_array(bar) << std::endl;
} |
Partager