namespace std
{
-
-template <class _Container>
-class back_insert_iterator {
-protected:
- _Container* container;
-public:
- typedef _Container container_type;
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
-
- explicit back_insert_iterator(_Container& __x) : container(&__x) {}
- back_insert_iterator<_Container>&
- operator=(const typename _Container::value_type& __value) {
- container->push_back(__value);
- return *this;
- }
- back_insert_iterator<_Container>& operator*() { return *this; }
- back_insert_iterator<_Container>& operator++() { return *this; }
- back_insert_iterator<_Container>& operator++(int) { return *this; }
-};
-
-template <class _Container>
-inline back_insert_iterator<_Container> back_inserter(_Container& __x) {
- return back_insert_iterator<_Container>(__x);
-}
-
-template <class _Container>
-class front_insert_iterator {
-protected:
- _Container* container;
-public:
- typedef _Container container_type;
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
-
- explicit front_insert_iterator(_Container& __x) : container(&__x) {}
- front_insert_iterator<_Container>&
- operator=(const typename _Container::value_type& __value) {
- container->push_front(__value);
- return *this;
+ // 24.4.1 Reverse iterators
+ template<class _Iterator>
+ class reverse_iterator
+ : public iterator<iterator_traits<_Iterator>::iterator_category,
+ iterator_traits<_Iterator>::value_type,
+ iterator_traits<_Iterator>::difference_type,
+ iterator_traits<_Iterator>::pointer,
+ iterator_traits<_Iterator>::reference>
+ {
+ protected:
+ _Iterator current;
+
+ public:
+ typedef iterator_traits<_Iterator> __traits_type;
+ typedef typename __traits_type::iterator_category iterator_category;
+ typedef typename __traits_type::value_type value_type;
+ typedef typename __traits_type::difference_type difference_type;
+ typedef typename __traits_type::pointer pointer;
+ typedef typename __traits_type::reference reference;
+
+ typedef _Iterator iterator_type;
+ typedef reverse_iterator<_Iterator> _Self;
+
+ public:
+ reverse_iterator() {}
+
+ explicit
+ reverse_iterator(iterator_type __x) : current(__x) {}
+
+ reverse_iterator(const _Self& __x) : current(__x.current) {}
+
+ template <class _Iter>
+ reverse_iterator(const reverse_iterator<_Iter>& __x)
+ : current(__x.base()) {}
+
+ iterator_type
+ base() const { return current; }
+
+ reference
+ operator*() const
+ {
+ _Iterator __tmp = current;
+ return *--__tmp;
+ }
+
+ pointer
+ operator->() const { return &(operator*()); }
+
+ _Self&
+ operator++()
+ {
+ --current;
+ return *this;
+ }
+
+ _Self
+ operator++(int)
+ {
+ _Self __tmp = *this;
+ --current;
+ return __tmp;
+ }
+
+ _Self&
+ operator--()
+ {
+ ++current;
+ return *this;
+ }
+
+ _Self operator--(int)
+ {
+ _Self __tmp = *this;
+ ++current;
+ return __tmp;
+ }
+
+ _Self
+ operator+(difference_type __n) const
+ { return _Self(current - __n); }
+
+ _Self&
+ operator+=(difference_type __n)
+ {
+ current -= __n;
+ return *this;
+ }
+
+ _Self
+ operator-(difference_type __n) const
+ { return _Self(current + __n); }
+
+ _Self&
+ operator-=(difference_type __n)
+ {
+ current += __n;
+ return *this;
+ }
+
+ reference
+ operator[](difference_type __n) const { return *(*this + __n); }
+ };
+
+ template<class _Iterator>
+ inline bool
+ operator==(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __x.base() == __y.base(); }
+
+ template <class _Iterator>
+ inline bool
+ operator<(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __y.base() < __x.base(); }
+
+ template <class _Iterator>
+ inline bool
+ operator!=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__x == __y); }
+
+ template <class _Iterator>
+ inline bool
+ operator>(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __y < __x; }
+
+ template <class _Iterator>
+ inline bool
+ operator<=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__y < __x); }
+
+ template <class _Iterator>
+ inline bool
+ operator>=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__x < __y); }
+
+ template<class _Iterator>
+ inline typename reverse_iterator<_Iterator>::difference_type
+ operator-(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __y.base() - __x.base(); }
+
+ template <class _Iterator>
+ inline reverse_iterator<_Iterator>
+ operator+(typename reverse_iterator<_Iterator>::difference_type __n,
+ const reverse_iterator<_Iterator>& __x)
+ { return reverse_iterator<_Iterator>(__x.base() - __n); }
+
+ // 24.4.2.2.1 back_insert_iterator
+ template <class _Container>
+ class back_insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+
+ public:
+ typedef _Container container_type;
+
+ explicit
+ back_insert_iterator(_Container& __x) : container(&__x) {}
+
+ back_insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value)
+ {
+ container->push_back(__value);
+ return *this;
+ }
+
+ back_insert_iterator<_Container>&
+ operator*() { return *this; }
+
+ back_insert_iterator<_Container>&
+ operator++() { return *this; }
+
+ back_insert_iterator<_Container>&
+ operator++(int) { return *this; }
+ };
+
+ template <class _Container>
+ inline back_insert_iterator<_Container>
+ back_inserter(_Container& __x)
+ { return back_insert_iterator<_Container>(__x); }
+
+ template <class _Container>
+ class front_insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+
+ public:
+ typedef _Container container_type;
+
+ explicit front_insert_iterator(_Container& __x) : container(&__x) {}
+ front_insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value) {
+ container->push_front(__value);
+ return *this;
+ }
+ front_insert_iterator<_Container>& operator*() { return *this; }
+ front_insert_iterator<_Container>& operator++() { return *this; }
+ front_insert_iterator<_Container>& operator++(int) { return *this; }
+ };
+
+ template <class _Container>
+ inline front_insert_iterator<_Container> front_inserter(_Container& __x) {
+ return front_insert_iterator<_Container>(__x);
}
- front_insert_iterator<_Container>& operator*() { return *this; }
- front_insert_iterator<_Container>& operator++() { return *this; }
- front_insert_iterator<_Container>& operator++(int) { return *this; }
-};
-
-template <class _Container>
-inline front_insert_iterator<_Container> front_inserter(_Container& __x) {
- return front_insert_iterator<_Container>(__x);
-}
-template <class _Container>
-class insert_iterator {
-protected:
- _Container* container;
- typename _Container::iterator iter;
-public:
- typedef _Container container_type;
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
-
- insert_iterator(_Container& __x, typename _Container::iterator __i)
- : container(&__x), iter(__i) {}
- insert_iterator<_Container>&
- operator=(const typename _Container::value_type& __value) {
- iter = container->insert(iter, __value);
- ++iter;
- return *this;
+ template <class _Container>
+ class insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+ typename _Container::iterator iter;
+
+ public:
+ typedef _Container container_type;
+
+ insert_iterator(_Container& __x, typename _Container::iterator __i)
+ : container(&__x), iter(__i) {}
+
+ insert_iterator<_Container>&
+ operator=(const typename _Container::value_type& __value) {
+ iter = container->insert(iter, __value);
+ ++iter;
+ return *this;
+ }
+ insert_iterator<_Container>& operator*() { return *this; }
+ insert_iterator<_Container>& operator++() { return *this; }
+ insert_iterator<_Container>& operator++(int) { return *this; }
+ };
+
+ template <class _Container, class _Iterator>
+ inline
+ insert_iterator<_Container> inserter(_Container& __x, _Iterator __i)
+ {
+ typedef typename _Container::iterator __iter;
+ return insert_iterator<_Container>(__x, __iter(__i));
}
- insert_iterator<_Container>& operator*() { return *this; }
- insert_iterator<_Container>& operator++() { return *this; }
- insert_iterator<_Container>& operator++(int) { return *this; }
-};
-
-template <class _Container, class _Iterator>
-inline
-insert_iterator<_Container> inserter(_Container& __x, _Iterator __i)
-{
- typedef typename _Container::iterator __iter;
- return insert_iterator<_Container>(__x, __iter(__i));
-}
-
-template <class _BidirectionalIterator, class _Tp, class _Reference = _Tp&,
- class _Distance = ptrdiff_t>
-class reverse_bidirectional_iterator {
- typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
- _Reference, _Distance> _Self;
-protected:
- _BidirectionalIterator current;
-public:
- typedef bidirectional_iterator_tag iterator_category;
+
+ template <class _BidirectionalIterator, class _Tp, class _Reference = _Tp&,
+ class _Distance = ptrdiff_t>
+ class reverse_bidirectional_iterator {
+ typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
+ _Reference, _Distance> _Self;
+ protected:
+ _BidirectionalIterator current;
+ public:
+ typedef bidirectional_iterator_tag iterator_category;
typedef _Tp value_type;
- typedef _Distance difference_type;
+ typedef _Distance difference_type;
typedef _Tp* pointer;
- typedef _Reference reference;
-
+ typedef _Reference reference;
+
reverse_bidirectional_iterator() {}
- explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
- : current(__x) {}
- _BidirectionalIterator base() const { return current; }
- _Reference operator*() const {
- _BidirectionalIterator __tmp = current;
+ explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
+ : current(__x) {}
+ _BidirectionalIterator base() const { return current; }
+ _Reference operator*() const {
+ _BidirectionalIterator __tmp = current;
return *--__tmp;
}
pointer operator->() const { return &(operator*()); }
}
-// This is the new version of reverse_iterator, as defined in the
-// draft C++ standard. It relies on the iterator_traits template,
-// which in turn relies on partial specialization. The class
-// reverse_bidirectional_iterator is no longer part of the draft
-// standard, but it is retained for backward compatibility.
-
-template <class _Iterator>
-class reverse_iterator
-{
-protected:
- _Iterator current;
-public:
- typedef typename iterator_traits<_Iterator>::iterator_category
- iterator_category;
- typedef typename iterator_traits<_Iterator>::value_type
- value_type;
- typedef typename iterator_traits<_Iterator>::difference_type
- difference_type;
- typedef typename iterator_traits<_Iterator>::pointer
- pointer;
- typedef typename iterator_traits<_Iterator>::reference
- reference;
-
- typedef _Iterator iterator_type;
- typedef reverse_iterator<_Iterator> _Self;
-
-public:
- reverse_iterator() {}
- explicit reverse_iterator(iterator_type __x) : current(__x) {}
-
- reverse_iterator(const _Self& __x) : current(__x.current) {}
- template <class _Iter>
- reverse_iterator(const reverse_iterator<_Iter>& __x)
- : current(__x.base()) {}
-
- iterator_type base() const { return current; }
- reference operator*() const {
- _Iterator __tmp = current;
- return *--__tmp;
- }
- pointer operator->() const { return &(operator*()); }
-
- _Self& operator++() {
- --current;
- return *this;
- }
- _Self operator++(int) {
- _Self __tmp = *this;
- --current;
- return __tmp;
- }
- _Self& operator--() {
- ++current;
- return *this;
- }
- _Self operator--(int) {
- _Self __tmp = *this;
- ++current;
- return __tmp;
- }
-
- _Self operator+(difference_type __n) const {
- return _Self(current - __n);
- }
- _Self& operator+=(difference_type __n) {
- current -= __n;
- return *this;
- }
- _Self operator-(difference_type __n) const {
- return _Self(current + __n);
- }
- _Self& operator-=(difference_type __n) {
- current += __n;
- return *this;
- }
- reference operator[](difference_type __n) const { return *(*this + __n); }
-};
-
-template <class _Iterator>
-inline bool operator==(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return __x.base() == __y.base();
-}
-
-template <class _Iterator>
-inline bool operator<(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return __y.base() < __x.base();
-}
-
-template <class _Iterator>
-inline bool operator!=(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return !(__x == __y);
-}
-
-template <class _Iterator>
-inline bool operator>(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return __y < __x;
-}
-
-template <class _Iterator>
-inline bool operator<=(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return !(__y < __x);
-}
-
-template <class _Iterator>
-inline bool operator>=(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return !(__x < __y);
-}
-
-template <class _Iterator>
-inline typename reverse_iterator<_Iterator>::difference_type
-operator-(const reverse_iterator<_Iterator>& __x,
- const reverse_iterator<_Iterator>& __y) {
- return __y.base() - __x.base();
-}
-
-template <class _Iterator>
-inline reverse_iterator<_Iterator>
-operator+(typename reverse_iterator<_Iterator>::difference_type __n,
- const reverse_iterator<_Iterator>& __x) {
- return reverse_iterator<_Iterator>(__x.base() - __n);
-}
-
template <class _Tp,
class _CharT = char, class _Traits = char_traits<_CharT>,
public:
typedef __normal_iterator<_Iterator, _Container> normal_iterator_type;
- typedef iterator_traits<_Iterator> __traits_type;
- typedef typename __traits_type::iterator_category iterator_category;
- typedef typename __traits_type::value_type value_type;
- typedef typename __traits_type::difference_type difference_type;
- typedef typename __traits_type::pointer pointer;
- typedef typename __traits_type::reference reference;
__normal_iterator() : _M_current(_Iterator()) { }