epoc32/include/stdapis/stlport/stl/_iterator.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_H
    31 #define _STLP_INTERNAL_ITERATOR_H
    32 
    33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    34 # include <stl/_iterator_base.h>
    35 #endif
    36 
    37 _STLP_BEGIN_NAMESPACE
    38 
    39 #if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
    40 // This is the new version of reverse_iterator, as defined in the
    41 //  draft C++ standard.  It relies on the iterator_traits template,
    42 //  which in turn relies on partial specialization.  The class
    43 //  reverse_bidirectional_iterator is no longer part of the draft
    44 //  standard, but it is retained for backward compatibility.
    45 
    46 template <class _Iterator>
    47 class reverse_iterator : 
    48   public iterator<typename iterator_traits<_Iterator>::iterator_category,
    49                   typename iterator_traits<_Iterator>::value_type,
    50                   typename iterator_traits<_Iterator>::difference_type,
    51                   typename iterator_traits<_Iterator>::pointer,
    52                   typename iterator_traits<_Iterator>::reference>
    53 {
    54 protected:
    55   _Iterator current;
    56   typedef reverse_iterator<_Iterator> _Self;
    57 public:
    58   typedef typename iterator_traits<_Iterator>::iterator_category  iterator_category;
    59   typedef typename iterator_traits<_Iterator>::value_type value_type;
    60   typedef typename iterator_traits<_Iterator>::difference_type difference_type;
    61   typedef typename iterator_traits<_Iterator>::pointer pointer;
    62   typedef typename iterator_traits<_Iterator>::reference reference;
    63   typedef _Iterator iterator_type;
    64 public:
    65   reverse_iterator() {}
    66   explicit reverse_iterator(iterator_type __x) : current(__x) {}
    67   reverse_iterator(const _Self& __x) : current(__x.current) {}
    68   _Self& operator = (const _Self& __x) { current = __x.base(); return *this; } 
    69 #ifdef _STLP_MEMBER_TEMPLATES
    70   template <class _Iter>
    71   reverse_iterator(const reverse_iterator<_Iter>& __x) : current(__x.base()) {}
    72   template <class _Iter>
    73   _Self& operator = (const reverse_iterator<_Iter>& __x) { current = __x.base(); return *this; } 
    74 #endif /* _STLP_MEMBER_TEMPLATES */
    75     
    76   iterator_type base() const { return current; }
    77   reference operator*() const {
    78     _Iterator __tmp = current;
    79     return *--__tmp;
    80   }
    81   _STLP_DEFINE_ARROW_OPERATOR
    82   _Self& operator++() {
    83     --current;
    84     return *this;
    85   }
    86   _Self operator++(int) {
    87     _Self __tmp = *this;
    88     --current;
    89     return __tmp;
    90   }
    91   _Self& operator--() {
    92     ++current;
    93     return *this;
    94   }
    95   _Self operator--(int) {
    96     _Self __tmp = *this;
    97     ++current;
    98     return __tmp;
    99   }
   100 
   101   _Self operator+(difference_type __n) const {
   102     return _Self(current - __n);
   103   }
   104   _Self& operator+=(difference_type __n) {
   105     current -= __n;
   106     return *this;
   107   }
   108   _Self operator-(difference_type __n) const {
   109     return _Self(current + __n);
   110   }
   111   _Self& operator-=(difference_type __n) {
   112     current += __n;
   113     return *this;
   114   }
   115   reference operator[](difference_type __n) const { return *(*this + __n); }  
   116 }; 
   117  
   118 template <class _Iterator>
   119 inline bool  _STLP_CALL operator==(const reverse_iterator<_Iterator>& __x, 
   120                        const reverse_iterator<_Iterator>& __y) {
   121   return __x.base() == __y.base();
   122 }
   123 
   124 template <class _Iterator>
   125 inline bool _STLP_CALL operator<(const reverse_iterator<_Iterator>& __x, 
   126                       const reverse_iterator<_Iterator>& __y) {
   127   return __y.base() < __x.base();
   128 }
   129 
   130 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   131 
   132 template <class _Iterator>
   133 inline bool _STLP_CALL operator!=(const reverse_iterator<_Iterator>& __x, 
   134                        const reverse_iterator<_Iterator>& __y) {
   135   return !(__x == __y);
   136 }
   137 
   138 template <class _Iterator>
   139 inline bool _STLP_CALL operator>(const reverse_iterator<_Iterator>& __x, 
   140                       const reverse_iterator<_Iterator>& __y) {
   141   return __y < __x;
   142 }
   143 
   144 template <class _Iterator>
   145 inline bool _STLP_CALL operator<=(const reverse_iterator<_Iterator>& __x, 
   146                        const reverse_iterator<_Iterator>& __y) {
   147   return !(__y < __x);
   148 }
   149 
   150 template <class _Iterator>
   151 inline bool _STLP_CALL operator>=(const reverse_iterator<_Iterator>& __x, 
   152                       const reverse_iterator<_Iterator>& __y) {
   153   return !(__x < __y);
   154 }
   155 
   156 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
   157 
   158 template <class _Iterator>
   159 # ifdef __SUNPRO_CC
   160 inline ptrdiff_t _STLP_CALL
   161 # else
   162 inline typename reverse_iterator<_Iterator>::difference_type _STLP_CALL
   163 # endif
   164 operator-(const reverse_iterator<_Iterator>& __x, 
   165           const reverse_iterator<_Iterator>& __y) {
   166   return __y.base() - __x.base();
   167 }
   168 
   169 template <class _Iterator, class _DifferenceType>
   170 inline reverse_iterator<_Iterator>  _STLP_CALL
   171 operator+(_DifferenceType n,const reverse_iterator<_Iterator>& x) {
   172   return x.operator+(n);
   173 }
   174 
   175 # endif
   176 
   177 template <class _Container>
   178 class back_insert_iterator 
   179   : public iterator<output_iterator_tag,void,void,void,void>
   180 {
   181 protected:
   182   _Container* container;
   183 public:
   184   typedef _Container          container_type;
   185   typedef output_iterator_tag iterator_category;
   186 
   187   explicit back_insert_iterator(_Container& __x) : container(&__x) {}
   188   back_insert_iterator<_Container>&
   189   operator=(const typename _Container::value_type& __val) { 
   190     container->push_back(__val);
   191     return *this;
   192   }
   193   back_insert_iterator<_Container>& operator*() { return *this; }
   194   back_insert_iterator<_Container>& operator++() { return *this; }
   195   back_insert_iterator<_Container>  operator++(int) { return *this; }
   196 };
   197 
   198 template <class _Container>
   199 inline back_insert_iterator<_Container>  _STLP_CALL back_inserter(_Container& __x) {
   200   return back_insert_iterator<_Container>(__x);
   201 }
   202 
   203 template <class _Container>
   204 class front_insert_iterator 
   205   : public iterator<output_iterator_tag,void,void,void,void>
   206 {
   207 protected:
   208   _Container* container;
   209 public:
   210   typedef _Container          container_type;
   211   typedef output_iterator_tag iterator_category;
   212   explicit front_insert_iterator(_Container& __x) : container(&__x) {}
   213   front_insert_iterator<_Container>&
   214   operator=(const typename _Container::value_type& __val) { 
   215     container->push_front(__val);
   216     return *this;
   217   }
   218   front_insert_iterator<_Container>& operator*() { return *this; }
   219   front_insert_iterator<_Container>& operator++() { return *this; }
   220   front_insert_iterator<_Container>& operator++(int) { return *this; }
   221 };
   222 
   223 template <class _Container>
   224 inline front_insert_iterator<_Container>  _STLP_CALL front_inserter(_Container& __x) {
   225   return front_insert_iterator<_Container>(__x);
   226 }
   227 
   228 template <class _Container>
   229 class insert_iterator 
   230   : public iterator<output_iterator_tag,void,void,void,void>
   231 {
   232 protected:
   233   _Container* container;
   234   typename _Container::iterator iter;
   235 public:
   236   typedef _Container          container_type;
   237   typedef output_iterator_tag iterator_category;
   238   insert_iterator(_Container& __x, typename _Container::iterator __i) 
   239     : container(&__x), iter(__i) {}
   240   insert_iterator<_Container>&
   241   operator=(const typename _Container::value_type& __val) { 
   242     iter = container->insert(iter, __val);
   243     ++iter;
   244     return *this;
   245   }
   246   insert_iterator<_Container>& operator*() { return *this; }
   247   insert_iterator<_Container>& operator++() { return *this; }
   248   insert_iterator<_Container>& operator++(int) { return *this; }
   249 };
   250 
   251 template <class _Container, class _Iterator>
   252 inline insert_iterator<_Container>  _STLP_CALL
   253 inserter(_Container& __x, _Iterator __i)
   254 {
   255   typedef typename _Container::iterator __iter;
   256   return insert_iterator<_Container>(__x, __iter(__i));
   257 }
   258 
   259 _STLP_END_NAMESPACE
   260 
   261 #if ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
   262 # include <stl/_iterator_old.h>
   263 #endif /* __NO_PARTIAL_SPEC || ANACHRONISMS */
   264 
   265 #endif /* _STLP_INTERNAL_ITERATOR_H */
   266 
   267 // Local Variables:
   268 // mode:C++
   269 // End: