1 // Boost.Range library 2 // 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) 7 // 8 // For more information, see http://www.boost.org/libs/range/ 9 // 10 11 #ifndef BOOST_RANGE_ADAPTOR_INDIRECTED_HPP 12 #define BOOST_RANGE_ADAPTOR_INDIRECTED_HPP 13 14 #include <boost/range/iterator_range.hpp> 15 #include <boost/range/concepts.hpp> 16 #include <boost/iterator/indirect_iterator.hpp> 17 18 namespace boost 19 { 20 namespace range_detail 21 { 22 template< class R > 23 struct indirected_range : 24 public boost::iterator_range< 25 boost::indirect_iterator< 26 BOOST_DEDUCED_TYPENAME range_iterator<R>::type 27 > 28 > 29 { 30 private: 31 typedef boost::iterator_range< 32 boost::indirect_iterator< 33 BOOST_DEDUCED_TYPENAME range_iterator<R>::type 34 > 35 > 36 base; 37 38 public: indirected_rangeboost::range_detail::indirected_range39 explicit indirected_range( R& r ) 40 : base( r ) 41 { } 42 }; 43 44 struct indirect_forwarder {}; 45 46 template< class SinglePassRange > 47 inline indirected_range<SinglePassRange> operator |(SinglePassRange & r,indirect_forwarder)48 operator|( SinglePassRange& r, indirect_forwarder ) 49 { 50 BOOST_RANGE_CONCEPT_ASSERT(( 51 SinglePassRangeConcept<SinglePassRange>)); 52 53 return indirected_range<SinglePassRange>( r ); 54 } 55 56 template< class SinglePassRange > 57 inline indirected_range<const SinglePassRange> operator |(const SinglePassRange & r,indirect_forwarder)58 operator|( const SinglePassRange& r, indirect_forwarder ) 59 { 60 BOOST_RANGE_CONCEPT_ASSERT(( 61 SinglePassRangeConcept<const SinglePassRange>)); 62 63 return indirected_range<const SinglePassRange>( r ); 64 } 65 66 } // 'range_detail' 67 68 using range_detail::indirected_range; 69 70 namespace adaptors 71 { 72 namespace 73 { 74 const range_detail::indirect_forwarder indirected = 75 range_detail::indirect_forwarder(); 76 } 77 78 template<class SinglePassRange> 79 inline indirected_range<SinglePassRange> indirect(SinglePassRange & rng)80 indirect(SinglePassRange& rng) 81 { 82 BOOST_RANGE_CONCEPT_ASSERT(( 83 SinglePassRangeConcept<SinglePassRange>)); 84 return indirected_range<SinglePassRange>(rng); 85 } 86 87 template<class SinglePassRange> 88 inline indirected_range<const SinglePassRange> indirect(const SinglePassRange & rng)89 indirect(const SinglePassRange& rng) 90 { 91 BOOST_RANGE_CONCEPT_ASSERT(( 92 SinglePassRangeConcept<const SinglePassRange>)); 93 94 return indirected_range<const SinglePassRange>(rng); 95 } 96 } // 'adaptors' 97 98 } 99 100 #endif 101