/Src/Dependencies/Boost/boost/range/sub_range.hpp

http://hadesmem.googlecode.com/ · C++ Header · 182 lines · 136 code · 36 blank · 10 comment · 0 complexity · 2b72a3ea51f3db7be9d622b1fc5caba1 MD5 · raw file

  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009.
  4. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  5. // distribution is subject to the Boost Software License, Version
  6. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. #ifndef BOOST_RANGE_SUB_RANGE_HPP
  12. #define BOOST_RANGE_SUB_RANGE_HPP
  13. #include <boost/detail/workaround.hpp>
  14. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  15. #pragma warning( push )
  16. #pragma warning( disable : 4996 )
  17. #endif
  18. #include <boost/range/config.hpp>
  19. #include <boost/range/iterator_range.hpp>
  20. #include <boost/range/value_type.hpp>
  21. #include <boost/range/size_type.hpp>
  22. #include <boost/range/difference_type.hpp>
  23. #include <boost/range/algorithm/equal.hpp>
  24. #include <boost/assert.hpp>
  25. #include <boost/type_traits/is_reference.hpp>
  26. #include <boost/type_traits/remove_reference.hpp>
  27. namespace boost
  28. {
  29. template< class ForwardRange >
  30. class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
  31. {
  32. typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t;
  33. typedef iterator_range< iterator_t > base;
  34. typedef BOOST_DEDUCED_TYPENAME base::impl impl;
  35. public:
  36. typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type;
  37. typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
  38. typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator;
  39. typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
  40. typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
  41. typedef BOOST_DEDUCED_TYPENAME base::reference reference;
  42. public: // for return value of front/back
  43. typedef BOOST_DEDUCED_TYPENAME
  44. boost::mpl::if_< boost::is_reference<reference>,
  45. const BOOST_DEDUCED_TYPENAME boost::remove_reference<reference>::type&,
  46. reference >::type const_reference;
  47. public:
  48. sub_range() : base()
  49. { }
  50. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
  51. sub_range( const sub_range& r )
  52. : base( static_cast<const base&>( r ) )
  53. { }
  54. #endif
  55. template< class ForwardRange2 >
  56. sub_range( ForwardRange2& r ) :
  57. #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
  58. base( impl::adl_begin( r ), impl::adl_end( r ) )
  59. #else
  60. base( r )
  61. #endif
  62. { }
  63. template< class ForwardRange2 >
  64. sub_range( const ForwardRange2& r ) :
  65. #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
  66. base( impl::adl_begin( r ), impl::adl_end( r ) )
  67. #else
  68. base( r )
  69. #endif
  70. { }
  71. template< class Iter >
  72. sub_range( Iter first, Iter last ) :
  73. base( first, last )
  74. { }
  75. template< class ForwardRange2 >
  76. sub_range& operator=( ForwardRange2& r )
  77. {
  78. base::operator=( r );
  79. return *this;
  80. }
  81. template< class ForwardRange2 >
  82. sub_range& operator=( const ForwardRange2& r )
  83. {
  84. base::operator=( r );
  85. return *this;
  86. }
  87. sub_range& operator=( const sub_range& r )
  88. {
  89. base::operator=( static_cast<const base&>(r) );
  90. return *this;
  91. }
  92. public:
  93. iterator begin() { return base::begin(); }
  94. const_iterator begin() const { return base::begin(); }
  95. iterator end() { return base::end(); }
  96. const_iterator end() const { return base::end(); }
  97. difference_type size() const { return base::size(); }
  98. public: // convenience
  99. reference front()
  100. {
  101. return base::front();
  102. }
  103. const_reference front() const
  104. {
  105. return base::front();
  106. }
  107. reference back()
  108. {
  109. return base::back();
  110. }
  111. const_reference back() const
  112. {
  113. return base::back();
  114. }
  115. reference operator[]( difference_type sz )
  116. {
  117. return base::operator[](sz);
  118. }
  119. const_reference operator[]( difference_type sz ) const
  120. {
  121. return base::operator[](sz);
  122. }
  123. };
  124. template< class ForwardRange, class ForwardRange2 >
  125. inline bool operator==( const sub_range<ForwardRange>& l,
  126. const sub_range<ForwardRange2>& r )
  127. {
  128. return boost::equal( l, r );
  129. }
  130. template< class ForwardRange, class ForwardRange2 >
  131. inline bool operator!=( const sub_range<ForwardRange>& l,
  132. const sub_range<ForwardRange2>& r )
  133. {
  134. return !boost::equal( l, r );
  135. }
  136. template< class ForwardRange, class ForwardRange2 >
  137. inline bool operator<( const sub_range<ForwardRange>& l,
  138. const sub_range<ForwardRange2>& r )
  139. {
  140. return iterator_range_detail::less_than( l, r );
  141. }
  142. } // namespace 'boost'
  143. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
  144. #pragma warning( pop )
  145. #endif
  146. #endif