3 // Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
11 #ifndef BOOST_RANGE_ADAPTOR_REVERSED_HPP
12 #define BOOST_RANGE_ADAPTOR_REVERSED_HPP
14 #include <boost/range/iterator_range.hpp>
15 #include <boost/range/concepts.hpp>
16 #include <boost/iterator/reverse_iterator.hpp>
20 namespace range_detail
23 struct reversed_range :
24 public boost::iterator_range<
25 boost::reverse_iterator<
26 BOOST_DEDUCED_TYPENAME range_iterator<R>::type
31 typedef boost::iterator_range<
32 boost::reverse_iterator<
33 BOOST_DEDUCED_TYPENAME range_iterator<R>::type
39 typedef boost::reverse_iterator<BOOST_DEDUCED_TYPENAME range_iterator<R>::type> iterator;
41 explicit reversed_range( R& r )
42 : base( iterator(boost::end(r)), iterator(boost::begin(r)) )
46 struct reverse_forwarder {};
48 template< class BidirectionalRange >
49 inline reversed_range<BidirectionalRange>
50 operator|( BidirectionalRange& r, reverse_forwarder )
52 BOOST_RANGE_CONCEPT_ASSERT((
53 BidirectionalRangeConcept<BidirectionalRange>));
55 return reversed_range<BidirectionalRange>( r );
58 template< class BidirectionalRange >
59 inline reversed_range<const BidirectionalRange>
60 operator|( const BidirectionalRange& r, reverse_forwarder )
62 BOOST_RANGE_CONCEPT_ASSERT((
63 BidirectionalRangeConcept<const BidirectionalRange>));
65 return reversed_range<const BidirectionalRange>( r );
70 using range_detail::reversed_range;
76 const range_detail::reverse_forwarder reversed =
77 range_detail::reverse_forwarder();
80 template<class BidirectionalRange>
81 inline reversed_range<BidirectionalRange>
82 reverse(BidirectionalRange& rng)
84 BOOST_RANGE_CONCEPT_ASSERT((
85 BidirectionalRangeConcept<BidirectionalRange>));
87 return reversed_range<BidirectionalRange>(rng);
90 template<class BidirectionalRange>
91 inline reversed_range<const BidirectionalRange>
92 reverse(const BidirectionalRange& rng)
94 BOOST_RANGE_CONCEPT_ASSERT((
95 BidirectionalRangeConcept<const BidirectionalRange>));
97 return reversed_range<const BidirectionalRange>(rng);