|
Boost Users : |
Subject: Re: [Boost-users] [iterators][range][rangeex] range concatenation
From: er (erwann.rogard_at_[hidden])
Date: 2010-01-09 08:13:57
er wrote:
> I am wondering if perhaps someone responsible for range_ex has
> implemented concat and would care to kindly share it (apparently it's
> not included in the vault).
>
Someone tells me I overlooked chain which works similarly, albeit for
single pass only. Very useful, thanks!
#include <iostream>
#include <vector>
#include <list>
#include <iterator>
#include <algorithm>
#include <boost/range.hpp>
#include <boost/range/chain.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/next_prior.hpp>
int main (int argc, char * const argv[]) {
typedef double val_;
typedef std::vector<val_> vec_;
typedef std::list<val_> list_;
vec_ seq0; seq0.push_back(1);
list_ seq1; seq1.push_back(2);
vec_ seq2; seq2.push_back(3); seq2.push_back(4);
vec_ seq3; seq2.push_back(5);
BOOST_AUTO(
chained,
boost::chain(seq0,
boost::chain(seq1,
boost::chain(seq2,seq3)
)
)
);
BOOST_ASSERT( *boost::begin(chained) == 1 ); // Warning : reference to
temporary
BOOST_ASSERT( *boost::next(boost::begin(chained),1) == 2);
BOOST_ASSERT( *boost::next(boost::begin(chained),2) == 3);
BOOST_ASSERT( *boost::next(boost::begin(chained),3) == 4);
BOOST_ASSERT( *boost::next(boost::begin(chained),4) == 5);
std::copy(
boost::begin(chained),
boost::end(chained),
std::ostream_iterator<val_>(std::cout, " ")
);
return 0;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net