Home | Libraries | People | FAQ | More |
The combine
function is
used to make one range from multiple ranges. The combine
function returns a combined_range
which is an iterator_range
of a zip_iterator
from
the Boost.Iterator library.
namespace boost { namespace range { template<typename IterTuple> class combined_range : public iterator_range<zip_iterator<IterTuple> > { public: combined_range(IterTuple first, IterTuple last); }; template<typename... Ranges> auto combine(Ranges&&... rngs) -> combined_range<decltype(boost::make_tuple(boost::begin(rngs)...))> } // namespace range } // namespace boost
r
in Ranges
,
r
is a model of Single Pass Range
or better.
combined_range<tuple<typename
range_iterator<Ranges>::type...>
>
r
in Ranges
.
#include <boost/range/combine.hpp> #include <boost/foreach.hpp> #include <iostream> #include <vector> #include <list> int main(int, const char*[]) { std::vector<int> v; std::list<char> l; for (int i = 0; i < 5; ++i) { v.push_back(i); l.push_back(static_cast<char>(i) + 'a'); } int ti; char tc; BOOST_FOREACH(boost::tie(ti, tc), boost::combine(v, l)) { std::cout << '(' << ti << ',' << tc << ')' << '\n'; } return 0; }
This produces the output:
(0,a) (1,b) (2,c) (3,d) (4,e)