Created
January 27, 2010 12:12
-
-
Save anonymous/287791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace result_of | |
{ | |
template<class R1, class R2> struct chain | |
{ | |
typedef typename | |
boost::range_detail::chain_iterator< | |
typename boost::range_const_iterator<R1>::type, | |
typename boost::range_const_iterator<R2>::type, | |
typename boost::add_const<typename boost::range_value<R1 const>::type>::type> | |
iterator; | |
typedef typename boost::iterator_range<iterator> type; | |
}; | |
} | |
template<class R> | |
struct Chainer : public boost::iterator_range<typename R::const_iterator> | |
{ | |
typedef boost::iterator_range<typename R::const_iterator> Base; | |
Chainer(R const & r) : Base(r) | |
{ } | |
template<class OtherR> | |
Chainer<typename result_of::chain<Base, OtherR>::type> | |
operator()(OtherR const & other) const | |
{ | |
return Chainer<typename result_of::chain<Base, OtherR>::type>( | |
boost::chain(*this, other)); | |
} | |
}; | |
template<class R1, class R2> | |
typename result_of::chain<R1, Chainer<R2> >::type | |
operator|(R1 const & r1, Chainer<R2> const & r2) | |
{ | |
return boost::chain(r1, r2); | |
} | |
template<class R> | |
Chainer<R> chain(R const & r) | |
{ | |
return Chainer<R>(r); | |
} | |
void test() | |
{ | |
namespace boost; | |
vector<int> a = force(counting_range(0, 5)); | |
deque<int> b = force(counting_range(10, 15)); | |
list<int> c = force(counting_range(20, 25)); | |
copy(a | chain(b) | chain(c), | |
ostream_iterator<int>(cout, "\n")); | |
copy(chain(a)(b)(c), | |
ostream_iterator<int>(cout, "\n")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment