
er skrev:
Dmitry Vinogradov wrote:
Is it possible with Boost (or RangeEx) to concatenate ranges?
Sample usage:
template <class Range> void process_range(Range const &);
std::vector<foo> v = ...; std::list<foo> l = ...; process_range(concat(v, l));
I take it you have a good reason not to simply copy v and l into a new container. iterator_facade might help, and iterator_range to obtain a range.
It will be impossible to implement a generic iterator that allows for fast iteration over the two ranges. The problem is that the iterator would have to check when the new container starts, similar to segments in a std::deque<T>. So I would just call process_range() twice. If you really need to view the two ranges as one range, then you have to pay an abstraction penalty, albeit it might be more efficiant than copying the two containers into a new one (and it is probably not that trivial to write the iterator that depends on two or more other iterator types). If "foo" is a heavy object, then copying the references of the elements to a new container std::vector<boost::reference_wrapper<foo>> is probably the most efficient alternative. -Thorsten