Boost Range Library: Traversing Two Ranges Sequentially

后端 未结 3 1675
日久生厌
日久生厌 2020-12-19 11:50

Boost range library (http://www.boost.org/doc/libs/1_35_0/libs/range/index.html) allows us to abstract a pair of iterators into a range. Now I want to combine two ranges int

3条回答
  •  执笔经年
    2020-12-19 12:05

    I needed this again so I had a second look. There is a way to concat two ranges using boost/range/join.hpp. Unluckily the output range type is not included in the interface:

    #include "boost/range/join.hpp"
    #include "boost/foreach.hpp"
    #include 
    
    int main() {
            int a[] = {1, 2, 3, 4};
            int b[] = {7, 2, 3, 4};
    
            boost::iterator_range ai(&a[0], &a[4]);
            boost::iterator_range bi(&b[0], &b[4]);
            boost::iterator_range<
               boost::range_detail::
               join_iterator > ci = boost::join(ai, bi); 
    
            BOOST_FOREACH(int& i, ci) {
                    std::cout << i; //prints 12347234
            }
    }
    

    I found the output type using the compiler messages. C++0x auto will be relevant there as well.

提交回复
热议问题