epoc32/include/stdapis/stlport/stl/_iterator_base.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996-1998
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999 
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted 
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    31 #define _STLP_INTERNAL_ITERATOR_BASE_H
    32 
    33 #ifndef _STLP_CSTDDEF
    34 # include <cstddef>
    35 #endif
    36 
    37 # if defined  (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
    38 _STLP_BEGIN_NAMESPACE  
    39 using namespace _STLP_VENDOR_CSTD;
    40 _STLP_END_NAMESPACE
    41 #endif /* _STLP_IMPORT_VENDOR_CSTD */
    42 
    43 #ifndef __TYPE_TRAITS_H
    44 # include <stl/type_traits.h>
    45 #endif
    46 
    47 _STLP_BEGIN_NAMESPACE
    48 
    49 struct input_iterator_tag {};
    50 struct output_iterator_tag {};
    51 struct forward_iterator_tag : public input_iterator_tag {};
    52 struct bidirectional_iterator_tag : public forward_iterator_tag {};
    53 struct random_access_iterator_tag : public bidirectional_iterator_tag {};
    54 
    55 
    56 template <class _Category, class _Tp, __DFL_TMPL_PARAM(_Distance,ptrdiff_t),
    57           __DFL_TMPL_PARAM(_Pointer,_Tp*), __DFL_TMPL_PARAM(_Reference,_Tp&) >
    58 struct iterator {
    59   typedef _Category  iterator_category;
    60   typedef _Tp        value_type;
    61   typedef _Distance  difference_type;
    62   typedef _Pointer   pointer;
    63   typedef _Reference reference;
    64 };
    65 _STLP_TEMPLATE_NULL
    66 struct iterator<output_iterator_tag, void, void, void, void> {
    67   typedef output_iterator_tag  iterator_category;
    68 #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
    69   typedef void                value_type;
    70   typedef void                difference_type;
    71   typedef void                pointer;
    72   typedef void                reference;
    73 #endif
    74 };
    75 
    76 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
    77 #  define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_category(_It)
    78 #  define _STLP_DISTANCE_TYPE(_It, _Tp)     distance_type(_It)
    79 #  define _STLP_VALUE_TYPE(_It, _Tp)        value_type(_It)
    80 # else
    81 #  ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
    82 #   define _STLP_VALUE_TYPE(_It, _Tp)        (typename iterator_traits< _Tp >::value_type*)0
    83 #   define _STLP_DISTANCE_TYPE(_It, _Tp)     (typename iterator_traits< _Tp >::difference_type*)0
    84 #   if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || ( defined (__sgi) && defined (_COMPILER_VERSION)) || defined (__DMC__)
    85 #    define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_traits< _Tp >::iterator_category()
    86 #   else
    87 #    define _STLP_ITERATOR_CATEGORY(_It, _Tp) typename iterator_traits< _Tp >::iterator_category()
    88 #   endif
    89 #  else
    90 #   define _STLP_ITERATOR_CATEGORY(_It, _Tp) __iterator_category(_It, _IsPtrType<_Tp>::_Ret())
    91 #   define _STLP_DISTANCE_TYPE(_It, _Tp)     (ptrdiff_t*)0
    92 #   define _STLP_VALUE_TYPE(_It, _Tp)        __value_type(_It, _IsPtrType<_Tp>::_Ret() )
    93 #  endif
    94 # endif
    95 
    96 template <class _Iterator>
    97 struct iterator_traits {
    98   typedef typename _Iterator::iterator_category iterator_category;
    99   typedef typename _Iterator::value_type        value_type;
   100   typedef typename _Iterator::difference_type   difference_type;
   101   typedef typename _Iterator::pointer           pointer;
   102   typedef typename _Iterator::reference         reference;
   103 };
   104 
   105 
   106 # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (__SUNPRO_CC)
   107 #  define _STLP_DIFFERENCE_TYPE(_Iterator) typename iterator_traits<_Iterator>::difference_type
   108 # else
   109 #  define _STLP_DIFFERENCE_TYPE(_Iterator) ptrdiff_t
   110 # endif
   111 
   112 # ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
   113 
   114 // fbp : this order keeps gcc happy
   115 template <class _Tp>
   116 struct iterator_traits<const _Tp*> {
   117   typedef random_access_iterator_tag iterator_category;
   118   typedef _Tp                         value_type;
   119   typedef ptrdiff_t                   difference_type;
   120   typedef const _Tp*                  pointer;
   121   typedef const _Tp&                  reference;
   122 };
   123 
   124 template <class _Tp>
   125 struct iterator_traits<_Tp*> {
   126   typedef random_access_iterator_tag iterator_category;
   127   typedef _Tp                         value_type;
   128   typedef ptrdiff_t                   difference_type;
   129   typedef _Tp*                        pointer;
   130   typedef _Tp&                        reference;
   131 };
   132 
   133 #  if defined (__BORLANDC__)
   134 template <class _Tp>
   135 struct iterator_traits<_Tp* const> {
   136   typedef random_access_iterator_tag iterator_category;
   137   typedef _Tp                         value_type;
   138   typedef ptrdiff_t                   difference_type;
   139   typedef const _Tp*                  pointer;
   140   typedef const _Tp&                  reference;
   141 };
   142 #  endif
   143 
   144 # endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   145 
   146 
   147 # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) \
   148   || (defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && ! defined (_STLP_NO_ARROW_OPERATOR))
   149 #  define _STLP_POINTERS_SPECIALIZE( _TpP )
   150 #  define _STLP_DEFINE_ARROW_OPERATOR  pointer operator->() const { return &(operator*()); }
   151 # else 
   152 #  include <stl/_ptrs_specialize.h>
   153 # endif
   154 
   155 # ifndef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   156 // The overloaded functions iterator_category, distance_type, and
   157 // value_type are not part of the C++ standard.  (They have been
   158 // replaced by struct iterator_traits.)  They are included for
   159 // backward compatibility with the HP STL.
   160 // We introduce internal names for these functions.
   161 
   162 #  ifdef  _STLP_CLASS_PARTIAL_SPECIALIZATION
   163 
   164 template <class _Iter>
   165 inline typename iterator_traits<_Iter>::iterator_category __iterator_category(const _Iter&) {
   166   typedef typename iterator_traits<_Iter>::iterator_category _Category;
   167   return _Category();
   168 }
   169 
   170 template <class _Iter>
   171 inline typename iterator_traits<_Iter>::difference_type* __distance_type(const _Iter&) {
   172   typedef typename iterator_traits<_Iter>::difference_type _diff_type;
   173   return __STATIC_CAST(_diff_type*,0);
   174 }
   175 
   176 template <class _Iter>
   177 inline typename iterator_traits<_Iter>::value_type* __value_type(const _Iter&) {
   178   typedef typename iterator_traits<_Iter>::value_type _value_type;
   179   return __STATIC_CAST(_value_type*,0);
   180 }
   181 
   182 # else
   183 
   184 template <class _Iter>
   185 inline random_access_iterator_tag 
   186 __iterator_category(const _Iter&, const __true_type&) {
   187   return random_access_iterator_tag();
   188 }
   189 
   190 template <class _Iter>
   191 inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::iterator_category
   192 __iterator_category(const _Iter&, const __false_type&) {
   193   typedef typename iterator_traits<_Iter>::iterator_category _Category;
   194   return _Category();
   195 }
   196 
   197 
   198 template <class _Iter>
   199 inline ptrdiff_t* _STLP_CALL __distance_type(const _Iter&) { return (ptrdiff_t*)(0); }
   200 
   201 template <class _Iter>
   202 inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::value_type* 
   203 __value_type(const _Iter&, const __false_type&) {
   204   typedef typename iterator_traits<_Iter>::value_type _value_type;
   205   return __STATIC_CAST(_value_type*,0);
   206 }
   207 
   208 template <class _Tp>
   209 inline _Tp*  
   210 __value_type(const _Tp*, const __true_type&) {
   211   return __STATIC_CAST(_Tp*, 0);
   212 }
   213 
   214 # endif
   215 
   216 #else /* old queries */
   217 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
   218 inline _Category _STLP_CALL iterator_category(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return _Category(); }
   219 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
   220 inline _Tp* _STLP_CALL value_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Tp*)(0); }
   221 template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
   222 inline _Distance* _STLP_CALL distance_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Distance*)(0); }
   223 template <class _Tp>
   224 inline random_access_iterator_tag _STLP_CALL iterator_category(const _Tp*) { return random_access_iterator_tag(); }
   225 template <class _Tp>
   226 inline _Tp* _STLP_CALL value_type(const _Tp*) { return (_Tp*)(0); }
   227 template <class _Tp>
   228 inline ptrdiff_t* _STLP_CALL distance_type(const _Tp*) { return (ptrdiff_t*)(0); }
   229 #endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
   230 
   231 # if ! defined (_STLP_NO_ANACHRONISMS)
   232 // The base classes input_iterator, output_iterator, forward_iterator,
   233 // bidirectional_iterator, and random_access_iterator are not part of
   234 // the C++ standard.  (They have been replaced by struct iterator.)
   235 // They are included for backward compatibility with the HP STL.
   236 template <class _Tp, class _Distance> struct input_iterator : 
   237   public iterator <input_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
   238 struct output_iterator : public iterator <output_iterator_tag, void, void, void, void> {};
   239 template <class _Tp, class _Distance> struct forward_iterator :
   240   public iterator<forward_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
   241 template <class _Tp, class _Distance> struct bidirectional_iterator :
   242   public iterator<bidirectional_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
   243 template <class _Tp, class _Distance> struct random_access_iterator :
   244   public iterator<random_access_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
   245 
   246 # if defined (_STLP_BASE_MATCH_BUG) && defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
   247 template <class _Tp, class _Distance> 
   248 inline input_iterator_tag _STLP_CALL 
   249 iterator_category(const input_iterator<_Tp, _Distance>&) { return input_iterator_tag(); }
   250 inline output_iterator_tag _STLP_CALL
   251 iterator_category(const output_iterator&) { return output_iterator_tag(); }
   252 template <class _Tp, class _Distance> 
   253 inline forward_iterator_tag _STLP_CALL
   254 iterator_category(const forward_iterator<_Tp, _Distance>&) { return forward_iterator_tag(); }
   255 template <class _Tp, class _Distance> 
   256 inline bidirectional_iterator_tag _STLP_CALL 
   257 iterator_category(const bidirectional_iterator<_Tp, _Distance>&) { return bidirectional_iterator_tag(); }
   258 template <class _Tp, class _Distance> 
   259 inline random_access_iterator_tag _STLP_CALL
   260 iterator_category(const random_access_iterator<_Tp, _Distance>&) { return random_access_iterator_tag(); }
   261 template <class _Tp, class _Distance> 
   262 inline _Tp*  _STLP_CALL value_type(const input_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
   263 template <class _Tp, class _Distance> 
   264 inline _Tp* _STLP_CALL value_type(const forward_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
   265 template <class _Tp, class _Distance> 
   266 inline _Tp* _STLP_CALL value_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
   267 template <class _Tp, class _Distance> 
   268 inline _Tp* _STLP_CALL value_type(const random_access_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
   269 template <class _Tp, class _Distance> 
   270 inline _Distance* _STLP_CALL distance_type(const input_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
   271 template <class _Tp, class _Distance> 
   272 inline _Distance* _STLP_CALL distance_type(const forward_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
   273 template <class _Tp, class _Distance> 
   274 inline _Distance* _STLP_CALL distance_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Distance*)(0);}
   275 template <class _Tp, class _Distance> 
   276 inline _Distance* _STLP_CALL distance_type(const random_access_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
   277 # endif /* BASE_MATCH */
   278 
   279 #endif /* _STLP_NO_ANACHRONISMS */
   280 
   281 template <class _InputIterator, class _Distance>
   282 inline void _STLP_CALL __distance(const _InputIterator& __first, const _InputIterator& __last,
   283 				  _Distance& __n, const input_iterator_tag &) {
   284   _InputIterator __it(__first);
   285   while (__it != __last) { ++__it; ++__n; }
   286 }
   287 
   288 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG) 
   289 template <class _ForwardIterator, class _Distance>
   290 inline void _STLP_CALL __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
   291 				  _Distance& __n, const forward_iterator_tag &) {
   292   _ForwardIterator __it(__first);
   293   while (__it != __last) { ++__first; ++__n; }
   294 }
   295 
   296 template <class _BidirectionalIterator, class _Distance>
   297 _STLP_INLINE_LOOP void _STLP_CALL __distance(const _BidirectionalIterator& __first, 
   298 					     const _BidirectionalIterator& __last,
   299 					     _Distance& __n, const bidirectional_iterator_tag &) {
   300   _BidirectionalIterator __it(__first);
   301   while (__it != __last) { ++__it; ++__n; }
   302 }
   303 # endif
   304 
   305 template <class _RandomAccessIterator, class _Distance>
   306 inline void _STLP_CALL __distance(const _RandomAccessIterator& __first, 
   307 				  const _RandomAccessIterator& __last, 
   308 				  _Distance& __n, const random_access_iterator_tag &) {
   309   __n += __last - __first;
   310 }
   311 
   312 #ifndef _STLP_NO_ANACHRONISMS 
   313 template <class _InputIterator, class _Distance>
   314 inline void _STLP_CALL distance(const _InputIterator& __first, 
   315 				const _InputIterator& __last, _Distance& __n) {
   316   __distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   317 }
   318 #endif
   319 
   320 template <class _InputIterator>
   321 inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
   322 __distance(const _InputIterator& __first, const _InputIterator& __last, const input_iterator_tag &) {
   323   _STLP_DIFFERENCE_TYPE(_InputIterator) __n = 0;
   324   _InputIterator __it(__first);  
   325   while (__it != __last) {
   326     ++__it; ++__n;
   327   }
   328   return __n;
   329 }
   330 
   331 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG) 
   332 template <class _ForwardIterator>
   333 inline _STLP_DIFFERENCE_TYPE(_ForwardIterator) _STLP_CALL 
   334 __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
   335            const forward_iterator_tag &)
   336 {
   337   _STLP_DIFFERENCE_TYPE(_ForwardIterator) __n = 0;
   338   _ForwardIterator __it(__first);
   339   while (__it != __last) {
   340     ++__it; ++__n;
   341   }
   342   return __n;
   343 }
   344 
   345 template <class _BidirectionalIterator>
   346 _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) _STLP_CALL 
   347 __distance(const _BidirectionalIterator& __first, 
   348            const _BidirectionalIterator& __last,
   349            const bidirectional_iterator_tag &) {
   350   _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) __n = 0;
   351   _BidirectionalIterator __it(__first);
   352   while (__it != __last) {
   353     ++__it; ++__n;
   354   }
   355   return __n;
   356 }
   357 # endif
   358 
   359 template <class _RandomAccessIterator>
   360 inline _STLP_DIFFERENCE_TYPE(_RandomAccessIterator) _STLP_CALL
   361 __distance(const _RandomAccessIterator& __first, const _RandomAccessIterator& __last,
   362            const random_access_iterator_tag &) {
   363   return __last - __first;
   364 }
   365 
   366 template <class _InputIterator>
   367 inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
   368 distance(const _InputIterator& __first, const _InputIterator& __last) {
   369   return __distance(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));  
   370 }
   371 
   372 
   373 // fbp: those are being used for iterator/const_iterator definitions everywhere
   374 template <class _Tp>
   375 struct _Nonconst_traits;
   376 
   377 template <class _Tp>
   378 struct _Const_traits {
   379   typedef _Tp value_type;
   380   typedef const _Tp&  reference;
   381   typedef const _Tp*  pointer;
   382   typedef _Nonconst_traits<_Tp> _Non_const_traits;
   383 };
   384 
   385 template <class _Tp>
   386 struct _Nonconst_traits {
   387   typedef _Tp value_type;
   388   typedef _Tp& reference;
   389   typedef _Tp* pointer;
   390   typedef _Nonconst_traits<_Tp> _Non_const_traits;
   391 };
   392 
   393 #  if defined (_STLP_BASE_TYPEDEF_BUG)
   394 // this workaround is needed for SunPro 4.0.1
   395 template <class _Traits>
   396 struct __cnst_traits_aux : private _Traits
   397 {
   398   typedef typename _Traits::value_type value_type;
   399 };
   400 #  define __TRAITS_VALUE_TYPE(_Traits) __cnst_traits_aux<_Traits>::value_type
   401 #  else
   402 #  define __TRAITS_VALUE_TYPE(_Traits) _Traits::value_type
   403 #  endif
   404 
   405 # if defined (_STLP_MSVC)
   406 // MSVC specific
   407 template <class _InputIterator, class _Dist>
   408 inline void  _STLP_CALL _Distance(_InputIterator __first, 
   409 		      _InputIterator __last, _Dist& __n) {
   410   __distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   411 }
   412 # endif
   413 
   414 template <class _InputIter, class _Distance>
   415 _STLP_INLINE_LOOP void  _STLP_CALL __advance(_InputIter& __i, _Distance __n, const input_iterator_tag &) {
   416   while (__n--) ++__i;
   417 }
   418 
   419 // fbp : added output iterator tag variant
   420 template <class _InputIter, class _Distance>
   421 _STLP_INLINE_LOOP void  _STLP_CALL __advance(_InputIter& __i, _Distance __n, const output_iterator_tag &) {
   422   while (__n--) ++__i;
   423 }
   424 
   425 # if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
   426 template <class _ForwardIterator, class _Distance>
   427 _STLP_INLINE_LOOP void _STLP_CALL __advance(_ForwardIterator& i, _Distance n, const forward_iterator_tag &) {
   428     while (n--) ++i;
   429 }
   430 # endif
   431 
   432 template <class _BidirectionalIterator, class _Distance>
   433 _STLP_INLINE_LOOP void _STLP_CALL __advance(_BidirectionalIterator& __i, _Distance __n, 
   434                       const bidirectional_iterator_tag &) {
   435   if (__n > 0)
   436     while (__n--) ++__i;
   437   else
   438     while (__n++) --__i;
   439 }
   440 
   441 template <class _RandomAccessIterator, class _Distance>
   442 inline void _STLP_CALL __advance(_RandomAccessIterator& __i, _Distance __n, 
   443                       const random_access_iterator_tag &) {
   444   __i += __n;
   445 }
   446 
   447 template <class _InputIterator, class _Distance>
   448 inline void _STLP_CALL advance(_InputIterator& __i, _Distance __n) {
   449   __advance(__i, __n, _STLP_ITERATOR_CATEGORY(__i, _InputIterator));
   450 }
   451 
   452 _STLP_END_NAMESPACE
   453 
   454 # if defined (_STLP_DEBUG) && ! defined (_STLP_DEBUG_H)
   455 #  include <stl/debug/_debug.h>
   456 # endif
   457 
   458 #endif /* _STLP_INTERNAL_ITERATOR_BASE_H */
   459 
   460 
   461 // Local Variables:
   462 // mode:C++
   463 // End: