Acceleration Range Library: Move two ranges sequentially

The acceleration range library ( http://www.boost.org/doc/libs/1_35_0/libs/range/index.html ) allows you to abstract a couple of iterators in a range. Now I want to combine the two ranges into one, namely:

given the two ranges r1 and r2, define r that intersects [r1.begin (), r1.end () [and then [r2.begin (), r2.end () [. Is there a way to define r as a range using r1 and r2?

+4
source share
3 answers

I needed it again, so I got a second look. There is a way to concatenate two ranges using boost / range / join.hpp. Unfortunately, the type of output range is not included in the interface:

#include "boost/range/join.hpp"
#include "boost/foreach.hpp"
#include <iostream>

int main() {
        int a[] = {1, 2, 3, 4};
        int b[] = {7, 2, 3, 4};

        boost::iterator_range<int*> ai(&a[0], &a[4]);
        boost::iterator_range<int*> bi(&b[0], &b[4]);
        boost::iterator_range<
           boost::range_detail::
           join_iterator<int*, int*, int, int&, 
           boost::random_access_traversal_tag> > ci = boost::join(ai, bi); 

        BOOST_FOREACH(int& i, ci) {
                std::cout << i; //prints 12347234
        }
}

I found the type of output using compiler messages. C ++ 0x autowill also make a difference.

+6
source
  • Can you call the function twice, once for both ranges? Or is there a problem with this approach?
  • Copy the two ranges into one container and transfer it.
  • Write your own range class, so iterates through r1 first and through r2 second.
+1
source

, , "" r1.end() r2.begin(), r1.end(). Begin() end() r. AFAIK , .

0

All Articles