indirected.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef BOOST_RANGE_ADAPTOR_INDIRECTED_HPP
  11. #define BOOST_RANGE_ADAPTOR_INDIRECTED_HPP
  12. #include <boost/range/iterator_range.hpp>
  13. #include <boost/range/concepts.hpp>
  14. #include <boost/iterator/indirect_iterator.hpp>
  15. namespace boost
  16. {
  17. namespace range_detail
  18. {
  19. template< class R >
  20. struct indirected_range :
  21. public boost::iterator_range<
  22. boost::indirect_iterator<
  23. BOOST_DEDUCED_TYPENAME range_iterator<R>::type
  24. >
  25. >
  26. {
  27. private:
  28. typedef boost::iterator_range<
  29. boost::indirect_iterator<
  30. BOOST_DEDUCED_TYPENAME range_iterator<R>::type
  31. >
  32. >
  33. base;
  34. public:
  35. explicit indirected_range( R& r )
  36. : base( r )
  37. { }
  38. };
  39. struct indirect_forwarder {};
  40. template< class SinglePassRange >
  41. inline indirected_range<SinglePassRange>
  42. operator|( SinglePassRange& r, indirect_forwarder )
  43. {
  44. BOOST_RANGE_CONCEPT_ASSERT((
  45. SinglePassRangeConcept<SinglePassRange>));
  46. return indirected_range<SinglePassRange>( r );
  47. }
  48. template< class SinglePassRange >
  49. inline indirected_range<const SinglePassRange>
  50. operator|( const SinglePassRange& r, indirect_forwarder )
  51. {
  52. BOOST_RANGE_CONCEPT_ASSERT((
  53. SinglePassRangeConcept<const SinglePassRange>));
  54. return indirected_range<const SinglePassRange>( r );
  55. }
  56. } // 'range_detail'
  57. using range_detail::indirected_range;
  58. namespace adaptors
  59. {
  60. namespace
  61. {
  62. const range_detail::indirect_forwarder indirected =
  63. range_detail::indirect_forwarder();
  64. }
  65. template<class SinglePassRange>
  66. inline indirected_range<SinglePassRange>
  67. indirect(SinglePassRange& rng)
  68. {
  69. BOOST_RANGE_CONCEPT_ASSERT((
  70. SinglePassRangeConcept<SinglePassRange>));
  71. return indirected_range<SinglePassRange>(rng);
  72. }
  73. template<class SinglePassRange>
  74. inline indirected_range<const SinglePassRange>
  75. indirect(const SinglePassRange& rng)
  76. {
  77. BOOST_RANGE_CONCEPT_ASSERT((
  78. SinglePassRangeConcept<const SinglePassRange>));
  79. return indirected_range<const SinglePassRange>(rng);
  80. }
  81. } // 'adaptors'
  82. }
  83. #endif