00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00043 #ifndef RANGELIB_INCL_RANGELIB_HPP_INDEXED_RANGE
00044 #define RANGELIB_INCL_RANGELIB_HPP_INDEXED_RANGE
00045
00046 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00047 # define RANGELIB_VER_RANGELIB_HPP_INDEXED_RANGE_MAJOR 2
00048 # define RANGELIB_VER_RANGELIB_HPP_INDEXED_RANGE_MINOR 4
00049 # define RANGELIB_VER_RANGELIB_HPP_INDEXED_RANGE_REVISION 2
00050 # define RANGELIB_VER_RANGELIB_HPP_INDEXED_RANGE_EDIT 33
00051 #endif
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef RANGELIB_INCL_RANGELIB_HPP_RANGELIB
00070 # include <rangelib/rangelib.hpp>
00071 #endif
00072
00073 #if defined(STLSOFT_COMPILER_IS_BORLAND) || \
00074 ( defined(STLSOFT_COMPILER_IS_MWERKS) && \
00075 ((__MWERKS__ & 0xFF00) < 0x3000))
00076 # error This file is not compatible with the current compiler
00077 #endif
00078
00079 #ifndef STLSOFT_INCL_STLSOFT_META_HPP_CAPABILITIES
00080 # include <stlsoft/meta/capabilities.hpp>
00081 #endif
00082 #if defined(STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED)
00083 # ifndef STLSOFT_INCL_STLSOFT_META_HPP_MEMBER_TRAITS
00084 # include <stlsoft/meta/member_traits.hpp>
00085 # endif
00086 # ifndef STLSOFT_INCL_STLSOFT_META_TYPEFIXER_HPP_REFERENCE
00087 # include <stlsoft/meta/typefixer/reference.hpp>
00088 # endif
00089 #endif
00090 #ifndef RANGELIB_INCL_RANGELIB_HPP_OPERATOR_ADAPTORS
00091 # include <rangelib/operator_adaptors.hpp>
00092 #endif
00093 #ifdef STLSOFT_UNITTEST
00094 # ifndef RANGELIB_INCL_RANGELIB_HPP_INTEGRAL_RANGE
00095 # include <rangelib/integral_range.hpp>
00096 # endif
00097 #endif
00098
00099
00100
00101
00102
00103 #ifndef RANGELIB_NO_NAMESPACE
00104 # if defined(_STLSOFT_NO_NAMESPACE) || \
00105 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00106
00107 namespace rangelib
00108 {
00109 # else
00110
00111
00112 namespace stlsoft
00113 {
00114
00115 namespace rangelib_project
00116 {
00117
00118 # endif
00119 #endif
00120
00121
00122
00123
00124
00132 template< class R
00133 , ss_typename_param_k I = int
00134 >
00135 class indexed_range
00136 #if defined(STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED)
00137 : public operator_adaptor_selector<indexed_range<R, I>, R>::type
00138 #else
00139 : public non_mutating_operator_adaptor< indexed_range<R, I>, R>
00140 #endif
00141 , public R::range_tag_type
00142 {
00145 private:
00146 #ifdef STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED
00153 # if defined(STLSOFT_COMPILER_IS_MWERKS)
00154 enum { HAS_MEMBER_REFERENCE = 0 != member_traits<R>::has_member_reference };
00155 # else
00156 enum { HAS_MEMBER_REFERENCE = 0 != member_traits<R>::has_member_iterator };
00157 # endif
00158 #endif
00159
00160 public:
00162 typedef R adapted_range_type;
00164 typedef I index_type;
00166 #if !defined(STLSOFT_COMPILER_IS_MSVC) || \
00167 _MSC_VER > 1200
00168 typedef ss_typename_type_k R::range_tag_type range_tag_type;
00169 #endif
00171 typedef ss_typename_type_k R::value_type value_type;
00173 typedef ss_typename_type_k R::const_reference const_reference;
00174 #ifdef STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED
00176 typedef ss_typename_type_k select_first_type_if< ss_typename_type_k ::stlsoft::typefixer::fixer_reference<R, HAS_MEMBER_REFERENCE>::reference
00177 , const_reference
00178 , HAS_MEMBER_REFERENCE
00179 >::type reference;
00180 #endif
00182 typedef indexed_range<R, I> class_type;
00184
00187 public:
00192 ss_explicit_k indexed_range(R r, index_type index = 0)
00193 : m_range(r)
00194 , m_index(index)
00195 {}
00197
00200 public:
00202 ss_bool_t is_open() const
00203 {
00204 return m_range.is_open();
00205 }
00206 #ifdef STLSOFT_CF_HAS_MEMBER_TYPE_SUPPORTED
00208 reference current()
00209 {
00210 STLSOFT_ASSERT(is_open());
00211
00212 return m_range.current();
00213 }
00214 #endif
00216 const_reference current() const
00217 {
00218 STLSOFT_ASSERT(is_open());
00219
00220 return m_range.current();
00221 }
00223 class_type& advance()
00224 {
00225 STLSOFT_MESSAGE_ASSERT("Attempting to increment the range past its end point", is_open());
00226
00227 ++m_range;
00228 ++m_index;
00229
00230 return *this;
00231 }
00233
00234 #if 0
00237 public:
00239 iterator begin()
00240 {
00241 return m_range.begin();
00242 }
00244 iterator end()
00245 {
00246 return m_range.end();
00247 }
00248
00250 const_iterator begin() const
00251 {
00252 return m_range.begin();
00253 }
00255 const_iterator end() const
00256 {
00257 return m_range.end();
00258 }
00260 #endif
00261
00264 public:
00265 index_type index() const
00266 {
00267 return m_index;
00268 }
00270
00271
00272 private:
00273 adapted_range_type m_range;
00274 index_type m_index;
00275 };
00276
00278
00279
00280 #ifdef STLSOFT_UNITTEST
00281 # include "./unittest/indexed_range_unittest_.h"
00282 #endif
00283
00284
00285
00286 #ifndef RANGELIB_NO_NAMESPACE
00287 # if defined(_STLSOFT_NO_NAMESPACE) || \
00288 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00289 }
00290 # else
00291 }
00292 }
00293 # endif
00294 #endif
00295
00296
00297
00298 #endif
00299
00300