_iterator_base.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  29. #define _STLP_INTERNAL_ITERATOR_BASE_H
  30. #ifndef _STLP_INTERNAL_CSTDDEF
  31. # include <stl/_cstddef.h>
  32. #endif
  33. //# if defined (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
  34. //_STLP_BEGIN_NAMESPACE
  35. //using namespace _STLP_VENDOR_CSTD;
  36. //_STLP_END_NAMESPACE
  37. //#endif /* _STLP_IMPORT_VENDOR_CSTD */
  38. #if !defined(_STLP_USE_OLD_HP_ITERATOR_QUERIES) && !defined(_STLP_CLASS_PARTIAL_SPECIALIZATION)
  39. # ifndef _STLP_TYPE_TRAITS_H
  40. # include <stl/type_traits.h>
  41. # endif
  42. #endif
  43. _STLP_BEGIN_NAMESPACE
  44. struct input_iterator_tag {};
  45. struct output_iterator_tag {};
  46. struct forward_iterator_tag : public input_iterator_tag {};
  47. struct bidirectional_iterator_tag : public forward_iterator_tag {};
  48. struct random_access_iterator_tag : public bidirectional_iterator_tag {};
  49. template <class _Category, class _Tp, _STLP_DFL_TMPL_PARAM(_Distance,ptrdiff_t),
  50. _STLP_DFL_TMPL_PARAM(_Pointer,_Tp*), _STLP_DFL_TMPL_PARAM(_Reference,_Tp&) >
  51. struct iterator {
  52. typedef _Category iterator_category;
  53. typedef _Tp value_type;
  54. typedef _Distance difference_type;
  55. typedef _Pointer pointer;
  56. typedef _Reference reference;
  57. };
  58. _STLP_TEMPLATE_NULL
  59. struct iterator<output_iterator_tag, void, void, void, void> {
  60. typedef output_iterator_tag iterator_category;
  61. #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
  62. typedef void value_type;
  63. typedef void difference_type;
  64. typedef void pointer;
  65. typedef void reference;
  66. #endif
  67. };
  68. #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  69. # define _STLP_ITERATOR_CATEGORY(_It, _Tp) _STLP_STD::iterator_category(_It)
  70. # define _STLP_DISTANCE_TYPE(_It, _Tp) _STLP_STD::distance_type(_It)
  71. # define _STLP_VALUE_TYPE(_It, _Tp) _STLP_STD::value_type(_It)
  72. //Old HP iterator queries do not give information about the iterator
  73. //associated reference type so we consider that it is not a real reference.
  74. # define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) __false_type()
  75. #else
  76. # if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  77. # define _STLP_VALUE_TYPE(_It, _Tp) (_STLP_TYPENAME _STLP_STD::iterator_traits< _Tp >::value_type*)0
  78. # define _STLP_DISTANCE_TYPE(_It, _Tp) (_STLP_TYPENAME _STLP_STD::iterator_traits< _Tp >::difference_type*)0
  79. # if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || \
  80. (defined (__sgi) && defined (_COMPILER_VERSION)) || defined (__DMC__)
  81. # define _STLP_ITERATOR_CATEGORY(_It, _Tp) _STLP_STD::iterator_traits< _Tp >::iterator_category()
  82. # else
  83. # define _STLP_ITERATOR_CATEGORY(_It, _Tp) _STLP_TYPENAME _STLP_STD::iterator_traits< _Tp >::iterator_category()
  84. # endif
  85. # define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) _STLP_STD::_IsRefType< _STLP_TYPENAME _STLP_STD::iterator_traits< _Tp >::reference >::_Ret()
  86. # else
  87. # define _STLP_ITERATOR_CATEGORY(_It, _Tp) _STLP_STD::__iterator_category(_It, _STLP_STD::_IsPtrType<_Tp>::_Ret())
  88. # define _STLP_DISTANCE_TYPE(_It, _Tp) _STLP_STD::__distance_type(_It, _STLP_STD::_IsPtrType<_Tp>::_Ret())
  89. # define _STLP_VALUE_TYPE(_It, _Tp) _STLP_STD::__value_type(_It, _STLP_STD::_IsPtrType<_Tp>::_Ret())
  90. # define _STLP_IS_REF_TYPE_REAL_REF(_It, _Tp) __false_type()
  91. # endif
  92. #endif
  93. #if defined (_STLP_DONT_REDEFINE_STD) && defined (_STLP_WHOLE_NATIVE_STD)
  94. /* In this mode we will see both STLport implementation and native
  95. * one. To allow some interaction between both implementations through
  96. * iterators we have to map std iterator categories to stlport ones. This
  97. * way we will be able to initialize STLport containers with native
  98. * iterators, the other side won't work except when STLport iterators are
  99. * simple pointers. */
  100. _STLP_END_NAMESPACE
  101. # if defined (_STLP_HAS_INCLUDE_NEXT)
  102. # include_next <iterator>
  103. # else
  104. # include _STLP_NATIVE_HEADER(iterator)
  105. # endif
  106. _STLP_BEGIN_NAMESPACE
  107. template <class _IteCat>
  108. struct _CategoryMapping
  109. { typedef _IteCat _Tag; };
  110. _STLP_TEMPLATE_NULL
  111. struct _CategoryMapping<::std::input_iterator_tag>
  112. { typedef input_iterator_tag _Tag; };
  113. _STLP_TEMPLATE_NULL
  114. struct _CategoryMapping<::std::output_iterator_tag>
  115. { typedef output_iterator_tag _Tag; };
  116. _STLP_TEMPLATE_NULL
  117. struct _CategoryMapping<::std::forward_iterator_tag>
  118. { typedef forward_iterator_tag _Tag; };
  119. _STLP_TEMPLATE_NULL
  120. struct _CategoryMapping<::std::bidirectional_iterator_tag>
  121. { typedef bidirectional_iterator_tag _Tag; };
  122. _STLP_TEMPLATE_NULL
  123. struct _CategoryMapping<::std::random_access_iterator_tag>
  124. { typedef random_access_iterator_tag _Tag; };
  125. template <class _Iterator>
  126. struct iterator_traits {
  127. typedef typename _Iterator::iterator_category _OriginalTag;
  128. typedef typename _CategoryMapping<_OriginalTag>::_Tag iterator_category;
  129. #else
  130. template <class _Iterator>
  131. struct iterator_traits {
  132. typedef typename _Iterator::iterator_category iterator_category;
  133. #endif
  134. typedef typename _Iterator::value_type value_type;
  135. typedef typename _Iterator::difference_type difference_type;
  136. typedef typename _Iterator::pointer pointer;
  137. typedef typename _Iterator::reference reference;
  138. };
  139. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (__SUNPRO_CC)
  140. # define _STLP_DIFFERENCE_TYPE(_Iterator) typename iterator_traits<_Iterator>::difference_type
  141. #else
  142. # define _STLP_DIFFERENCE_TYPE(_Iterator) ptrdiff_t
  143. #endif
  144. #ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
  145. // fbp : this order keeps gcc happy
  146. template <class _Tp>
  147. struct iterator_traits<const _Tp*> {
  148. typedef random_access_iterator_tag iterator_category;
  149. typedef _Tp value_type;
  150. typedef ptrdiff_t difference_type;
  151. typedef const _Tp* pointer;
  152. typedef const _Tp& reference;
  153. };
  154. template <class _Tp>
  155. struct iterator_traits<_Tp*> {
  156. typedef random_access_iterator_tag iterator_category;
  157. typedef _Tp value_type;
  158. typedef ptrdiff_t difference_type;
  159. typedef _Tp* pointer;
  160. typedef _Tp& reference;
  161. };
  162. # if defined (__BORLANDC__)
  163. template <class _Tp>
  164. struct iterator_traits<_Tp* const> {
  165. typedef random_access_iterator_tag iterator_category;
  166. typedef _Tp value_type;
  167. typedef ptrdiff_t difference_type;
  168. typedef const _Tp* pointer;
  169. typedef const _Tp& reference;
  170. };
  171. # endif
  172. #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
  173. _STLP_END_NAMESPACE
  174. #include <stl/_ptrs_specialize.h>
  175. _STLP_BEGIN_NAMESPACE
  176. #ifndef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  177. // The overloaded functions iterator_category, distance_type, and
  178. // value_type are not part of the C++ standard. (They have been
  179. // replaced by struct iterator_traits.) They are included for
  180. // backward compatibility with the HP STL.
  181. // We introduce internal names for these functions.
  182. # ifndef _STLP_CLASS_PARTIAL_SPECIALIZATION
  183. template <class _Tp>
  184. inline _STLP_STD::random_access_iterator_tag
  185. __iterator_category(const _Tp*, const __true_type&)
  186. { return _STLP_STD::random_access_iterator_tag(); }
  187. template <class _Iter>
  188. inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_STD::iterator_traits<_Iter>::iterator_category
  189. __iterator_category(const _Iter&, const __false_type&) {
  190. typedef _STLP_TYPENAME _STLP_STD::iterator_traits<_Iter>::iterator_category _Category;
  191. return _Category();
  192. }
  193. template <class _Tp>
  194. inline ptrdiff_t*
  195. __distance_type(const _Tp*, const __true_type&)
  196. { return __STATIC_CAST(ptrdiff_t*, 0); }
  197. template <class _Iter>
  198. inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_STD::iterator_traits<_Iter>::difference_type*
  199. __distance_type(const _Iter&, const __false_type&) {
  200. typedef _STLP_TYPENAME _STLP_STD::iterator_traits<_Iter>::difference_type _diff_type;
  201. return __STATIC_CAST(_diff_type*,0);
  202. }
  203. template <class _Tp>
  204. inline _Tp*
  205. __value_type(const _Tp*, const __true_type&)
  206. { return __STATIC_CAST(_Tp*, 0); }
  207. template <class _Iter>
  208. inline _STLP_TYPENAME_ON_RETURN_TYPE _STLP_STD::iterator_traits<_Iter>::value_type*
  209. __value_type(const _Iter&, const __false_type&) {
  210. typedef _STLP_TYPENAME _STLP_STD::iterator_traits<_Iter>::value_type _value_type;
  211. return __STATIC_CAST(_value_type*,0);
  212. }
  213. # endif
  214. #else /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
  215. template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
  216. inline _Category _STLP_CALL iterator_category(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return _Category(); }
  217. template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
  218. inline _Tp* _STLP_CALL value_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return __STATIC_CAST(_Tp*, 0); }
  219. template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
  220. inline _Distance* _STLP_CALL distance_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return __STATIC_CAST(_Distance*, 0); }
  221. template <class _Tp>
  222. inline random_access_iterator_tag _STLP_CALL iterator_category(const _Tp*) { return random_access_iterator_tag(); }
  223. template <class _Tp>
  224. inline _Tp* _STLP_CALL value_type(const _Tp*) { return __STATIC_CAST(_Tp*, 0); }
  225. template <class _Tp>
  226. inline ptrdiff_t* _STLP_CALL distance_type(const _Tp*) { return __STATIC_CAST(ptrdiff_t*, 0); }
  227. #endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
  228. #if !defined (_STLP_NO_ANACHRONISMS)
  229. // The base classes input_iterator, output_iterator, forward_iterator,
  230. // bidirectional_iterator, and random_access_iterator are not part of
  231. // the C++ standard. (They have been replaced by struct iterator.)
  232. // They are included for backward compatibility with the HP STL.
  233. template <class _Tp, class _Distance> struct input_iterator :
  234. public iterator <input_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
  235. struct output_iterator : public iterator <output_iterator_tag, void, void, void, void> {};
  236. template <class _Tp, class _Distance> struct forward_iterator :
  237. public iterator<forward_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
  238. template <class _Tp, class _Distance> struct bidirectional_iterator :
  239. public iterator<bidirectional_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
  240. template <class _Tp, class _Distance> struct random_access_iterator :
  241. public iterator<random_access_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
  242. # if defined (_STLP_BASE_MATCH_BUG) && defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  243. template <class _Tp, class _Distance>
  244. inline input_iterator_tag _STLP_CALL
  245. iterator_category(const input_iterator<_Tp, _Distance>&) { return input_iterator_tag(); }
  246. inline output_iterator_tag _STLP_CALL
  247. iterator_category(const output_iterator&) { return output_iterator_tag(); }
  248. template <class _Tp, class _Distance>
  249. inline forward_iterator_tag _STLP_CALL
  250. iterator_category(const forward_iterator<_Tp, _Distance>&) { return forward_iterator_tag(); }
  251. template <class _Tp, class _Distance>
  252. inline bidirectional_iterator_tag _STLP_CALL
  253. iterator_category(const bidirectional_iterator<_Tp, _Distance>&) { return bidirectional_iterator_tag(); }
  254. template <class _Tp, class _Distance>
  255. inline random_access_iterator_tag _STLP_CALL
  256. iterator_category(const random_access_iterator<_Tp, _Distance>&) { return random_access_iterator_tag(); }
  257. template <class _Tp, class _Distance>
  258. inline _Tp* _STLP_CALL value_type(const input_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
  259. template <class _Tp, class _Distance>
  260. inline _Tp* _STLP_CALL value_type(const forward_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
  261. template <class _Tp, class _Distance>
  262. inline _Tp* _STLP_CALL value_type(const bidirectional_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
  263. template <class _Tp, class _Distance>
  264. inline _Tp* _STLP_CALL value_type(const random_access_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Tp*, 0); }
  265. template <class _Tp, class _Distance>
  266. inline _Distance* _STLP_CALL distance_type(const input_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
  267. template <class _Tp, class _Distance>
  268. inline _Distance* _STLP_CALL distance_type(const forward_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
  269. template <class _Tp, class _Distance>
  270. inline _Distance* _STLP_CALL distance_type(const bidirectional_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0);}
  271. template <class _Tp, class _Distance>
  272. inline _Distance* _STLP_CALL distance_type(const random_access_iterator<_Tp, _Distance>&) { return __STATIC_CAST(_Distance*, 0); }
  273. # endif
  274. #endif
  275. _STLP_MOVE_TO_PRIV_NAMESPACE
  276. template <class _InputIterator>
  277. inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
  278. __distance(const _InputIterator& __first, const _InputIterator& __last,
  279. const input_iterator_tag &) {
  280. _STLP_DIFFERENCE_TYPE(_InputIterator) __n = 0;
  281. _InputIterator __it(__first);
  282. while (__it != __last) {
  283. ++__it; ++__n;
  284. }
  285. return __n;
  286. }
  287. #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
  288. template <class _ForwardIterator>
  289. inline _STLP_DIFFERENCE_TYPE(_ForwardIterator) _STLP_CALL
  290. __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
  291. const forward_iterator_tag &) {
  292. _STLP_DIFFERENCE_TYPE(_ForwardIterator) __n = 0;
  293. _ForwardIterator __it(__first);
  294. while (__it != __last) {
  295. ++__it; ++__n;
  296. }
  297. return __n;
  298. }
  299. template <class _BidirectionalIterator>
  300. _STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) _STLP_CALL
  301. __distance(const _BidirectionalIterator& __first, const _BidirectionalIterator& __last,
  302. const bidirectional_iterator_tag &) {
  303. _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) __n = 0;
  304. _BidirectionalIterator __it(__first);
  305. while (__it != __last) {
  306. ++__it; ++__n;
  307. }
  308. return __n;
  309. }
  310. #endif
  311. template <class _RandomAccessIterator>
  312. inline _STLP_DIFFERENCE_TYPE(_RandomAccessIterator) _STLP_CALL
  313. __distance(const _RandomAccessIterator& __first, const _RandomAccessIterator& __last,
  314. const random_access_iterator_tag &)
  315. { return __last - __first; }
  316. _STLP_MOVE_TO_STD_NAMESPACE
  317. template <class _InputIterator>
  318. inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
  319. distance(_InputIterator __first, _InputIterator __last)
  320. { return _STLP_PRIV __distance(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator)); }
  321. #if !defined (_STLP_NO_ANACHRONISMS)
  322. template <class _InputIterator, class _Distance>
  323. inline void _STLP_CALL distance(const _InputIterator& __first,
  324. const _InputIterator& __last, _Distance& __n)
  325. { __n += _STLP_STD::distance(__first, __last); }
  326. # if defined (_STLP_MSVC)
  327. // MSVC specific
  328. template <class _InputIterator, class _Dist>
  329. inline void _STLP_CALL _Distance(_InputIterator __first,
  330. _InputIterator __last, _Dist& __n)
  331. { __n += _STLP_STD::distance(__first, __last); }
  332. # endif
  333. #endif
  334. // fbp: those are being used for iterator/const_iterator definitions everywhere
  335. template <class _Tp>
  336. struct _Nonconst_traits;
  337. template <class _Tp>
  338. struct _Const_traits {
  339. typedef _Tp value_type;
  340. typedef const _Tp& reference;
  341. typedef const _Tp* pointer;
  342. typedef _Const_traits<_Tp> _ConstTraits;
  343. typedef _Nonconst_traits<_Tp> _NonConstTraits;
  344. };
  345. template <class _Tp>
  346. struct _Nonconst_traits {
  347. typedef _Tp value_type;
  348. typedef _Tp& reference;
  349. typedef _Tp* pointer;
  350. typedef _Const_traits<_Tp> _ConstTraits;
  351. typedef _Nonconst_traits<_Tp> _NonConstTraits;
  352. };
  353. /*
  354. * dums: A special iterator/const_iterator traits for set and multiset for which even
  355. * the iterator is not mutable
  356. */
  357. template <class _Tp>
  358. struct _Nonconst_Const_traits;
  359. template <class _Tp>
  360. struct _Const_Const_traits {
  361. typedef _Tp value_type;
  362. typedef const _Tp& reference;
  363. typedef const _Tp* pointer;
  364. typedef _Const_Const_traits<_Tp> _ConstTraits;
  365. typedef _Nonconst_Const_traits<_Tp> _NonConstTraits;
  366. };
  367. template <class _Tp>
  368. struct _Nonconst_Const_traits {
  369. typedef _Tp value_type;
  370. typedef const _Tp& reference;
  371. typedef const _Tp* pointer;
  372. typedef _Const_Const_traits<_Tp> _ConstTraits;
  373. typedef _Nonconst_Const_traits<_Tp> _NonConstTraits;
  374. };
  375. /*
  376. * A macro to generate a new iterator traits from one of the
  377. * previous one. Changing the iterator traits type make iterators
  378. * from different containers not comparable.
  379. */
  380. #define _STLP_CREATE_ITERATOR_TRAITS_BASE(Motif, Traits) \
  381. template <class _Tp> \
  382. struct _##Motif; \
  383. template <class _Tp> \
  384. struct _Const##Motif : public _STLP_STD::_Const_##Traits<_Tp> { \
  385. typedef _Const##Motif<_Tp> _ConstTraits; \
  386. typedef _##Motif<_Tp> _NonConstTraits; \
  387. }; \
  388. template <class _Tp> \
  389. struct _##Motif : public _STLP_STD::_Nonconst_##Traits<_Tp> { \
  390. typedef _Const##Motif<_Tp> _ConstTraits; \
  391. typedef _##Motif<_Tp> _NonConstTraits; \
  392. };
  393. #define _STLP_CREATE_ITERATOR_TRAITS(Motif, Traits) \
  394. _STLP_MOVE_TO_PRIV_NAMESPACE \
  395. _STLP_CREATE_ITERATOR_TRAITS_BASE(Motif, Traits) \
  396. _STLP_MOVE_TO_STD_NAMESPACE
  397. #define _STLP_CREATE_HASH_ITERATOR_TRAITS(Motif, Traits) \
  398. _STLP_MOVE_TO_PRIV_NAMESPACE \
  399. _STLP_CREATE_ITERATOR_TRAITS_BASE(NonLocal##Motif, Traits) \
  400. _STLP_CREATE_ITERATOR_TRAITS_BASE(Local##Motif, Traits) \
  401. template <class _Tp> \
  402. struct _##Motif { \
  403. typedef _ConstNonLocal##Motif<_Tp> _ConstTraits; \
  404. typedef _NonLocal##Motif<_Tp> _NonConstTraits; \
  405. typedef _ConstLocal##Motif<_Tp> _ConstLocalTraits; \
  406. typedef _Local##Motif<_Tp> _NonConstLocalTraits; \
  407. }; \
  408. _STLP_MOVE_TO_STD_NAMESPACE
  409. /*
  410. # if defined (_STLP_BASE_TYPEDEF_BUG)
  411. // this workaround is needed for SunPro 4.0.1
  412. template <class _Traits>
  413. struct __cnst_traits_aux : private _Traits {
  414. typedef typename _Traits::value_type value_type;
  415. };
  416. # define __TRAITS_VALUE_TYPE(_Traits) __cnst_traits_aux<_Traits>::value_type
  417. # else
  418. # define __TRAITS_VALUE_TYPE(_Traits) _Traits::value_type
  419. # endif
  420. */
  421. _STLP_MOVE_TO_PRIV_NAMESPACE
  422. template <class _InputIter, class _Distance>
  423. _STLP_INLINE_LOOP void _STLP_CALL
  424. __advance(_InputIter& __i, _Distance __n, const input_iterator_tag &)
  425. { while (__n--) ++__i; }
  426. // fbp : added output iterator tag variant
  427. template <class _InputIter, class _Distance>
  428. _STLP_INLINE_LOOP void _STLP_CALL
  429. __advance(_InputIter& __i, _Distance __n, const output_iterator_tag &)
  430. { while (__n--) ++__i; }
  431. #if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
  432. template <class _ForwardIterator, class _Distance>
  433. _STLP_INLINE_LOOP void _STLP_CALL
  434. __advance(_ForwardIterator& i, _Distance n, const forward_iterator_tag &)
  435. { while (n--) ++i; }
  436. #endif
  437. template <class _BidirectionalIterator, class _Distance>
  438. _STLP_INLINE_LOOP void _STLP_CALL
  439. __advance(_BidirectionalIterator& __i, _Distance __n,
  440. const bidirectional_iterator_tag &) {
  441. if (__n > 0)
  442. while (__n--) ++__i;
  443. else
  444. while (__n++) --__i;
  445. }
  446. template <class _RandomAccessIterator, class _Distance>
  447. inline void _STLP_CALL
  448. __advance(_RandomAccessIterator& __i, _Distance __n,
  449. const random_access_iterator_tag &)
  450. { __i += __n; }
  451. _STLP_MOVE_TO_STD_NAMESPACE
  452. template <class _InputIterator, class _Distance>
  453. inline void _STLP_CALL advance(_InputIterator& __i, _Distance __n)
  454. {
  455. _STLP_DIFFERENCE_TYPE(_InputIterator) __d = __n;
  456. _STLP_PRIV __advance(__i, __d, _STLP_ITERATOR_CATEGORY(__i, _InputIterator));
  457. }
  458. _STLP_END_NAMESPACE
  459. #endif /* _STLP_INTERNAL_ITERATOR_BASE_H */
  460. // Local Variables:
  461. // mode:C++
  462. // End: