#include <iostream> #include <vector> #include <boost/assign/list_of.hpp> #include <boost/range/combine.hpp> #include <boost/range/adaptor/sliced.hpp> #include <boost/foreach.hpp> int main() { const std::vector<int> v = boost::assign::list_of(1)(2)(3)(4)(5); if (v.size() < 2) return 0; using namespace boost::adaptors; typedef boost::tuple<int, int> value_type; BOOST_FOREACH (value_type x, boost::combine(v | sliced(0, v.size() - 1), v | sliced(1, v.size()))) { std::cout << boost::get<0>(x) << ',' << boost::get<1>(x) << std::endl; } }
1,2 2,3 3,4 4,5
点の配列があって、それらを線で結びたいときなどに。