+// Iterators -*- C++ -*-
+
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
/*
*
* Copyright (c) 1994
* purpose. It is provided "as is" without express or implied warranty.
*/
-/* NOTE: This is an internal header file, included by other STL headers.
- * You should not attempt to use it directly.
+/** @file stl_iterator.h
+ * This is an internal header file, included by other library headers.
+ * You should not attempt to use it directly.
+ *
+ * This file implements reverse_iterator, back_insert_iterator,
+ * front_insert_iterator, insert_iterator, __normal_iterator, and their
+ * supporting functions and overloaded operators.
*/
-#ifndef __SGI_STL_INTERNAL_ITERATOR_H
-#define __SGI_STL_INTERNAL_ITERATOR_H
-
-__STL_BEGIN_NAMESPACE
-
-
-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; }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _Container>
-inline output_iterator_tag
-iterator_category(const back_insert_iterator<_Container>&)
-{
- return output_iterator_tag();
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-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;
- }
- front_insert_iterator<_Container>& operator*() { return *this; }
- front_insert_iterator<_Container>& operator++() { return *this; }
- front_insert_iterator<_Container>& operator++(int) { return *this; }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _Container>
-inline output_iterator_tag
-iterator_category(const front_insert_iterator<_Container>&)
-{
- return output_iterator_tag();
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-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;
- }
- insert_iterator<_Container>& operator*() { return *this; }
- insert_iterator<_Container>& operator++() { return *this; }
- insert_iterator<_Container>& operator++(int) { return *this; }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _Container>
-inline output_iterator_tag
-iterator_category(const insert_iterator<_Container>&)
-{
- return output_iterator_tag();
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-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;
- typedef _Tp value_type;
- typedef _Distance difference_type;
- typedef _Tp* pointer;
- 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;
- return *--__tmp;
- }
-#ifndef __SGI_STL_NO_ARROW_OPERATOR
- pointer operator->() const { return &(operator*()); }
-#endif /* __SGI_STL_NO_ARROW_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;
- }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _BidirectionalIterator, class _Tp, class _Reference,
- class _Distance>
-inline bidirectional_iterator_tag
-iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator,
- _Tp, _Reference,
- _Distance>&)
-{
- return bidirectional_iterator_tag();
-}
-
-template <class _BidirectionalIterator, class _Tp, class _Reference,
- class _Distance>
-inline _Tp*
-value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
- _Reference, _Distance>&)
-{
- return (_Tp*) 0;
-}
-
-template <class _BidirectionalIterator, class _Tp, class _Reference,
- class _Distance>
-inline _Distance*
-distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator,
- _Tp,
- _Reference, _Distance>&)
-{
- return (_Distance*) 0;
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-template <class _BiIter, class _Tp, class _Ref, class _Distance>
-inline bool operator==(
- const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __x,
- const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __y)
-{
- return __x.base() == __y.base();
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-template <class _BiIter, class _Tp, class _Ref, class _Distance>
-inline bool operator!=(
- const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __x,
- const reverse_bidirectional_iterator<_BiIter, _Tp, _Ref, _Distance>& __y)
-{
- return !(__x == __y);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-
-#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-// 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) {}
-#ifdef __STL_MEMBER_TEMPLATES
- template <class _Iter>
- reverse_iterator(const reverse_iterator<_Iter>& __x)
- : current(__x.base()) {}
-#endif /* __STL_MEMBER_TEMPLATES */
-
- iterator_type base() const { return current; }
- reference operator*() const {
- _Iterator __tmp = current;
- return *--__tmp;
- }
-#ifndef __SGI_STL_NO_ARROW_OPERATOR
- pointer operator->() const { return &(operator*()); }
-#endif /* __SGI_STL_NO_ARROW_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();
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-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);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-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);
-}
-
-#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-// This is the old version of reverse_iterator, as found in the original
-// HP STL. It does not use partial specialization.
-
-template <class _RandomAccessIterator, class _Tp, class _Reference = _Tp&,
- class _Distance = ptrdiff_t>
-class reverse_iterator {
- typedef reverse_iterator<_RandomAccessIterator, _Tp, _Reference, _Distance>
- _Self;
-protected:
- _RandomAccessIterator current;
-public:
- typedef random_access_iterator_tag iterator_category;
- typedef _Tp value_type;
- typedef _Distance difference_type;
- typedef _Tp* pointer;
- typedef _Reference reference;
-
- reverse_iterator() {}
- explicit reverse_iterator(_RandomAccessIterator __x) : current(__x) {}
- _RandomAccessIterator base() const { return current; }
- _Reference operator*() const { return *(current - 1); }
-#ifndef __SGI_STL_NO_ARROW_OPERATOR
- pointer operator->() const { return &(operator*()); }
-#endif /* __SGI_STL_NO_ARROW_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+(_Distance __n) const {
- return _Self(current - __n);
- }
- _Self& operator+=(_Distance __n) {
- current -= __n;
- return *this;
- }
- _Self operator-(_Distance __n) const {
- return _Self(current + __n);
- }
- _Self& operator-=(_Distance __n) {
- current += __n;
- return *this;
- }
- _Reference operator[](_Distance __n) const { return *(*this + __n); }
-};
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline random_access_iterator_tag
-iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>&)
-{
- return random_access_iterator_tag();
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline _Tp* value_type(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>&)
-{
- return (_Tp*) 0;
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline _Distance*
-distance_type(const reverse_iterator<_RandomAccessIterator,
- _Tp, _Reference, _Distance>&)
-{
- return (_Distance*) 0;
-}
-
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y)
-{
- return __x.base() == __y.base();
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y)
-{
- return __y.base() < __x.base();
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y) {
- return !(__x == __y);
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y) {
- return __y < __x;
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y) {
- return !(__y < __x);
-}
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline bool
-operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y) {
- return !(__x < __y);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-template <class _RandomAccessIterator, class _Tp,
- class _Reference, class _Distance>
-inline _Distance
-operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __x,
- const reverse_iterator<_RandomAccessIterator, _Tp,
- _Reference, _Distance>& __y)
-{
- return __y.base() - __x.base();
-}
-
-template <class _RandAccIter, class _Tp, class _Ref, class _Dist>
-inline reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>
-operator+(_Dist __n,
- const reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>& __x)
-{
- return reverse_iterator<_RandAccIter, _Tp, _Ref, _Dist>(__x.base() - __n);
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-// istream_iterator and ostream_iterator look very different if we're
-// using new, templatized iostreams than if we're using the old cfront
-// version.
-
-#ifdef __STL_USE_NEW_IOSTREAMS
-
-template <class _Tp,
- class _CharT = char, class _Traits = char_traits<_CharT>,
- class _Dist = ptrdiff_t>
-class istream_iterator {
-public:
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef basic_istream<_CharT, _Traits> istream_type;
-
- typedef input_iterator_tag iterator_category;
- typedef _Tp value_type;
- typedef _Dist difference_type;
- typedef const _Tp* pointer;
- typedef const _Tp& reference;
-
- istream_iterator() : _M_stream(0), _M_ok(false) {}
- istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); }
-
- reference operator*() const { return _M_value; }
- pointer operator->() const { return &(operator*()); }
-
- istream_iterator& operator++() {
- _M_read();
- return *this;
- }
- istream_iterator operator++(int) {
- istream_iterator __tmp = *this;
- _M_read();
- return __tmp;
- }
-
- bool _M_equal(const istream_iterator& __x) const
- { return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); }
-
-private:
- istream_type* _M_stream;
- _Tp _M_value;
- bool _M_ok;
-
- void _M_read() {
- _M_ok = (_M_stream && *_M_stream) ? true : false;
- if (_M_ok) {
- *_M_stream >> _M_value;
- _M_ok = *_M_stream ? true : false;
+#ifndef _STL_ITERATOR_H
+#define _STL_ITERATOR_H 1
+
+#include <bits/cpp_type_traits.h>
+#include <ext/type_traits.h>
+#include <bits/move.h>
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
+ // 24.4.1 Reverse iterators
+ /**
+ * Bidirectional and random access iterators have corresponding reverse
+ * %iterator adaptors that iterate through the data structure in the
+ * opposite direction. They have the same signatures as the corresponding
+ * iterators. The fundamental relation between a reverse %iterator and its
+ * corresponding %iterator @c i is established by the identity:
+ * @code
+ * &*(reverse_iterator(i)) == &*(i - 1)
+ * @endcode
+ *
+ * <em>This mapping is dictated by the fact that while there is always a
+ * pointer past the end of an array, there might not be a valid pointer
+ * before the beginning of an array.</em> [24.4.1]/1,2
+ *
+ * Reverse iterators can be tricky and surprising at first. Their
+ * semantics make sense, however, and the trickiness is a side effect of
+ * the requirement that the iterators must be safe.
+ */
+ template<typename _Iterator>
+ class reverse_iterator
+ : public iterator<typename iterator_traits<_Iterator>::iterator_category,
+ typename iterator_traits<_Iterator>::value_type,
+ typename iterator_traits<_Iterator>::difference_type,
+ typename iterator_traits<_Iterator>::pointer,
+ typename iterator_traits<_Iterator>::reference>
+ {
+ protected:
+ _Iterator current;
+
+ typedef iterator_traits<_Iterator> __traits_type;
+
+ public:
+ typedef _Iterator iterator_type;
+ typedef typename __traits_type::difference_type difference_type;
+ typedef typename __traits_type::pointer pointer;
+ typedef typename __traits_type::reference reference;
+
+ /**
+ * The default constructor default-initializes member @p current.
+ * If it is a pointer, that means it is zero-initialized.
+ */
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 235 No specification of default ctor for reverse_iterator
+ reverse_iterator() : current() { }
+
+ /**
+ * This %iterator will move in the opposite direction that @p x does.
+ */
+ explicit
+ reverse_iterator(iterator_type __x) : current(__x) { }
+
+ /**
+ * The copy constructor is normal.
+ */
+ reverse_iterator(const reverse_iterator& __x)
+ : current(__x.current) { }
+
+ /**
+ * A reverse_iterator across other types can be copied in the normal
+ * fashion.
+ */
+ template<typename _Iter>
+ reverse_iterator(const reverse_iterator<_Iter>& __x)
+ : current(__x.base()) { }
+
+ /**
+ * @return @c current, the %iterator used for underlying work.
+ */
+ iterator_type
+ base() const
+ { return current; }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reference
+ operator*() const
+ {
+ _Iterator __tmp = current;
+ return *--__tmp;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ pointer
+ operator->() const
+ { return &(operator*()); }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator&
+ operator++()
+ {
+ --current;
+ return *this;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator
+ operator++(int)
+ {
+ reverse_iterator __tmp = *this;
+ --current;
+ return __tmp;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator&
+ operator--()
+ {
+ ++current;
+ return *this;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator
+ operator--(int)
+ {
+ reverse_iterator __tmp = *this;
+ ++current;
+ return __tmp;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator
+ operator+(difference_type __n) const
+ { return reverse_iterator(current - __n); }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator&
+ operator+=(difference_type __n)
+ {
+ current -= __n;
+ return *this;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator
+ operator-(difference_type __n) const
+ { return reverse_iterator(current + __n); }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reverse_iterator&
+ operator-=(difference_type __n)
+ {
+ current += __n;
+ return *this;
+ }
+
+ /**
+ * @return TODO
+ *
+ * @doctodo
+ */
+ reference
+ operator[](difference_type __n) const
+ { return *(*this + __n); }
+ };
+
+ //@{
+ /**
+ * @param x A %reverse_iterator.
+ * @param y A %reverse_iterator.
+ * @return A simple bool.
+ *
+ * Reverse iterators forward many operations to their underlying base()
+ * iterators. Others are implemented in terms of one another.
+ *
+ */
+ template<typename _Iterator>
+ inline bool
+ operator==(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __x.base() == __y.base(); }
+
+ template<typename _Iterator>
+ inline bool
+ operator<(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __y.base() < __x.base(); }
+
+ template<typename _Iterator>
+ inline bool
+ operator!=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__x == __y); }
+
+ template<typename _Iterator>
+ inline bool
+ operator>(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return __y < __x; }
+
+ template<typename _Iterator>
+ inline bool
+ operator<=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__y < __x); }
+
+ template<typename _Iterator>
+ inline bool
+ operator>=(const reverse_iterator<_Iterator>& __x,
+ const reverse_iterator<_Iterator>& __y)
+ { return !(__x < __y); }
+
+ template<typename _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<typename _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); }
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // DR 280. Comparison of reverse_iterator to const reverse_iterator.
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator==(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return __x.base() == __y.base(); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator<(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return __y.base() < __x.base(); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator!=(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return !(__x == __y); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator>(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return __y < __x; }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator<=(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return !(__y < __x); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator>=(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ { return !(__x < __y); }
+
+ template<typename _IteratorL, typename _IteratorR>
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ // DR 685.
+ inline auto
+ operator-(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+ -> decltype(__y.base() - __x.base())
+#else
+ inline typename reverse_iterator<_IteratorL>::difference_type
+ operator-(const reverse_iterator<_IteratorL>& __x,
+ const reverse_iterator<_IteratorR>& __y)
+#endif
+ { return __y.base() - __x.base(); }
+ //@}
+
+ // 24.4.2.2.1 back_insert_iterator
+ /**
+ * @brief Turns assignment into insertion.
+ *
+ * These are output iterators, constructed from a container-of-T.
+ * Assigning a T to the iterator appends it to the container using
+ * push_back.
+ *
+ * Tip: Using the back_inserter function to create these iterators can
+ * save typing.
+ */
+ template<typename _Container>
+ class back_insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+
+ public:
+ /// A nested typedef for the type of whatever container you used.
+ typedef _Container container_type;
+
+ /// The only way to create this %iterator is with a container.
+ explicit
+ back_insert_iterator(_Container& __x) : container(&__x) { }
+
+ /**
+ * @param value An instance of whatever type
+ * container_type::const_reference is; presumably a
+ * reference-to-const T for container<T>.
+ * @return This %iterator, for chained operations.
+ *
+ * This kind of %iterator doesn't really have a @a position in the
+ * container (you can think of the position as being permanently at
+ * the end, if you like). Assigning a value to the %iterator will
+ * always append the value to the end of the container.
+ */
+ back_insert_iterator&
+ operator=(typename _Container::const_reference __value)
+ {
+ container->push_back(__value);
+ return *this;
+ }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ back_insert_iterator&
+ operator=(typename _Container::value_type&& __value)
+ {
+ container->push_back(std::move(__value));
+ return *this;
+ }
+#endif
+
+ /// Simply returns *this.
+ back_insert_iterator&
+ operator*()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ back_insert_iterator&
+ operator++()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ back_insert_iterator
+ operator++(int)
+ { return *this; }
+ };
+
+ /**
+ * @param x A container of arbitrary type.
+ * @return An instance of back_insert_iterator working on @p x.
+ *
+ * This wrapper function helps in creating back_insert_iterator instances.
+ * Typing the name of the %iterator requires knowing the precise full
+ * type of the container, which can be tedious and impedes generic
+ * programming. Using this function lets you take advantage of automatic
+ * template parameter deduction, making the compiler match the correct
+ * types for you.
+ */
+ template<typename _Container>
+ inline back_insert_iterator<_Container>
+ back_inserter(_Container& __x)
+ { return back_insert_iterator<_Container>(__x); }
+
+ /**
+ * @brief Turns assignment into insertion.
+ *
+ * These are output iterators, constructed from a container-of-T.
+ * Assigning a T to the iterator prepends it to the container using
+ * push_front.
+ *
+ * Tip: Using the front_inserter function to create these iterators can
+ * save typing.
+ */
+ template<typename _Container>
+ class front_insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+
+ public:
+ /// A nested typedef for the type of whatever container you used.
+ typedef _Container container_type;
+
+ /// The only way to create this %iterator is with a container.
+ explicit front_insert_iterator(_Container& __x) : container(&__x) { }
+
+ /**
+ * @param value An instance of whatever type
+ * container_type::const_reference is; presumably a
+ * reference-to-const T for container<T>.
+ * @return This %iterator, for chained operations.
+ *
+ * This kind of %iterator doesn't really have a @a position in the
+ * container (you can think of the position as being permanently at
+ * the front, if you like). Assigning a value to the %iterator will
+ * always prepend the value to the front of the container.
+ */
+ front_insert_iterator&
+ operator=(typename _Container::const_reference __value)
+ {
+ container->push_front(__value);
+ return *this;
+ }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ front_insert_iterator&
+ operator=(typename _Container::value_type&& __value)
+ {
+ container->push_front(std::move(__value));
+ return *this;
+ }
+#endif
+
+ /// Simply returns *this.
+ front_insert_iterator&
+ operator*()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ front_insert_iterator&
+ operator++()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ front_insert_iterator
+ operator++(int)
+ { return *this; }
+ };
+
+ /**
+ * @param x A container of arbitrary type.
+ * @return An instance of front_insert_iterator working on @p x.
+ *
+ * This wrapper function helps in creating front_insert_iterator instances.
+ * Typing the name of the %iterator requires knowing the precise full
+ * type of the container, which can be tedious and impedes generic
+ * programming. Using this function lets you take advantage of automatic
+ * template parameter deduction, making the compiler match the correct
+ * types for you.
+ */
+ template<typename _Container>
+ inline front_insert_iterator<_Container>
+ front_inserter(_Container& __x)
+ { return front_insert_iterator<_Container>(__x); }
+
+ /**
+ * @brief Turns assignment into insertion.
+ *
+ * These are output iterators, constructed from a container-of-T.
+ * Assigning a T to the iterator inserts it in the container at the
+ * %iterator's position, rather than overwriting the value at that
+ * position.
+ *
+ * (Sequences will actually insert a @e copy of the value before the
+ * %iterator's position.)
+ *
+ * Tip: Using the inserter function to create these iterators can
+ * save typing.
+ */
+ template<typename _Container>
+ class insert_iterator
+ : public iterator<output_iterator_tag, void, void, void, void>
+ {
+ protected:
+ _Container* container;
+ typename _Container::iterator iter;
+
+ public:
+ /// A nested typedef for the type of whatever container you used.
+ typedef _Container container_type;
+
+ /**
+ * The only way to create this %iterator is with a container and an
+ * initial position (a normal %iterator into the container).
+ */
+ insert_iterator(_Container& __x, typename _Container::iterator __i)
+ : container(&__x), iter(__i) {}
+
+ /**
+ * @param value An instance of whatever type
+ * container_type::const_reference is; presumably a
+ * reference-to-const T for container<T>.
+ * @return This %iterator, for chained operations.
+ *
+ * This kind of %iterator maintains its own position in the
+ * container. Assigning a value to the %iterator will insert the
+ * value into the container at the place before the %iterator.
+ *
+ * The position is maintained such that subsequent assignments will
+ * insert values immediately after one another. For example,
+ * @code
+ * // vector v contains A and Z
+ *
+ * insert_iterator i (v, ++v.begin());
+ * i = 1;
+ * i = 2;
+ * i = 3;
+ *
+ * // vector v contains A, 1, 2, 3, and Z
+ * @endcode
+ */
+ insert_iterator&
+ operator=(typename _Container::const_reference __value)
+ {
+ iter = container->insert(iter, __value);
+ ++iter;
+ return *this;
+ }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ insert_iterator&
+ operator=(typename _Container::value_type&& __value)
+ {
+ iter = container->insert(iter, std::move(__value));
+ ++iter;
+ return *this;
+ }
+#endif
+
+ /// Simply returns *this.
+ insert_iterator&
+ operator*()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ insert_iterator&
+ operator++()
+ { return *this; }
+
+ /// Simply returns *this. (This %iterator does not @a move.)
+ insert_iterator&
+ operator++(int)
+ { return *this; }
+ };
+
+ /**
+ * @param x A container of arbitrary type.
+ * @return An instance of insert_iterator working on @p x.
+ *
+ * This wrapper function helps in creating insert_iterator instances.
+ * Typing the name of the %iterator requires knowing the precise full
+ * type of the container, which can be tedious and impedes generic
+ * programming. Using this function lets you take advantage of automatic
+ * template parameter deduction, making the compiler match the correct
+ * types for you.
+ */
+ template<typename _Container, typename _Iterator>
+ inline insert_iterator<_Container>
+ inserter(_Container& __x, _Iterator __i)
+ {
+ return insert_iterator<_Container>(__x,
+ typename _Container::iterator(__i));
}
- }
-};
-
-template <class _Tp, class _CharT, class _Traits, class _Dist>
-inline bool
-operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
- const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) {
- return __x._M_equal(__y);
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-template <class _Tp, class _CharT, class _Traits, class _Dist>
-inline bool
-operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x,
- const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) {
- return !__x._M_equal(__y);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-template <class _Tp,
- class _CharT = char, class _Traits = char_traits<_CharT> >
-class ostream_iterator {
-public:
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef basic_ostream<_CharT, _Traits> ostream_type;
-
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
-
- ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
- ostream_iterator(ostream_type& __s, const _CharT* __c)
- : _M_stream(&__s), _M_string(__c) {}
- ostream_iterator<_Tp>& operator=(const _Tp& __value) {
- *_M_stream << __value;
- if (_M_string) *_M_stream << _M_string;
- return *this;
- }
- ostream_iterator<_Tp>& operator*() { return *this; }
- ostream_iterator<_Tp>& operator++() { return *this; }
- ostream_iterator<_Tp>& operator++(int) { return *this; }
-private:
- ostream_type* _M_stream;
- const _CharT* _M_string;
-};
-
-// The default template argument is declared in iosfwd
-
-// We do not read any characters until operator* is called. The first
-// time operator* is called, it calls getc. Subsequent calls to getc
-// return a cached character, and calls to operator++ use snextc. Before
-// operator* or operator++ has been called, _M_is_initialized is false.
-template<class _CharT, class _Traits>
-class istreambuf_iterator
- : public iterator<input_iterator_tag, _CharT,
- typename _Traits::off_type, _CharT*, _CharT&>
-{
-public:
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef typename _Traits::int_type int_type;
- typedef basic_streambuf<_CharT, _Traits> streambuf_type;
- typedef basic_istream<_CharT, _Traits> istream_type;
-
-public:
- istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
- istreambuf_iterator(istream_type& __is) { this->_M_init(__is.rdbuf()); }
-
- char_type operator*() const
- { return _M_is_initialized ? _M_c : _M_dereference_aux(); }
-
- istreambuf_iterator& operator++() { this->_M_nextc(); return *this; }
- istreambuf_iterator operator++(int) {
- if (!_M_is_initialized)
- _M_postincr_aux();
- istreambuf_iterator __tmp = *this;
- this->_M_nextc();
- return __tmp;
- }
-
- bool equal(const istreambuf_iterator& __i) const {
- return this->_M_is_initialized && __i._M_is_initialized
- ? this->_M_eof == __i._M_eof
- : this->_M_equal_aux(__i);
- }
-
-private:
- void _M_init(streambuf_type* __p) {
- _M_buf = __p;
- _M_eof = !__p;
- _M_is_initialized = _M_eof;
- }
-
- char_type _M_dereference_aux() const;
- bool _M_equal_aux(const istreambuf_iterator&) const;
- void _M_postincr_aux();
-
- void _M_nextc() {
- int_type __c = _M_buf->snextc();
- _M_c = traits_type::to_char_type(__c);
- _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
- _M_is_initialized = true;
- }
-
- void _M_getc() const {
- int_type __c = _M_buf->sgetc();
- _M_c = traits_type::to_char_type(__c);
- _M_eof = traits_type::eq_int_type(__c, traits_type::eof());
- _M_is_initialized = true;
- }
-
-private:
- streambuf_type* _M_buf;
- mutable _CharT _M_c;
- mutable bool _M_eof : 1;
- mutable bool _M_is_initialized : 1;
-};
-
-template<class _CharT, class _Traits>
-_CharT istreambuf_iterator<_CharT, _Traits>::_M_dereference_aux() const
-{
- this->_M_getc();
- return _M_c;
-}
-
-template<class _CharT, class _Traits>
-bool istreambuf_iterator<_CharT, _Traits>
- ::_M_equal_aux(const istreambuf_iterator& __i) const
-{
- if (!this->_M_is_initialized)
- this->_M_getc();
- if (!__i._M_is_initialized)
- __i._M_getc();
-
- return this->_M_eof == __i._M_eof;
-}
-
-template<class _CharT, class _Traits>
-void istreambuf_iterator<_CharT, _Traits>::_M_postincr_aux()
-{
- this->_M_getc();
-}
-
-template<class _CharT, class _Traits>
-inline bool operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
- const istreambuf_iterator<_CharT, _Traits>& __y) {
- return __x.equal(__y);
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-template<class _CharT, class _Traits>
-inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
- const istreambuf_iterator<_CharT, _Traits>& __y) {
- return !__x.equal(__y);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-// The default template argument is declared in iosfwd
-template<class _CharT, class _Traits>
-class ostreambuf_iterator
- : public iterator<output_iterator_tag, void, void, void, void>
-{
-public:
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef typename _Traits::int_type int_type;
- typedef basic_streambuf<_CharT, _Traits> streambuf_type;
- typedef basic_ostream<_CharT, _Traits> ostream_type;
-
-public:
- ostreambuf_iterator(streambuf_type* __buf) : _M_buf(__buf), _M_ok(__buf) {}
- ostreambuf_iterator(ostream_type& __o)
- : _M_buf(__o.rdbuf()), _M_ok(__o.rdbuf() != 0) {}
-
- ostreambuf_iterator& operator=(char_type __c) {
- _M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c),
- traits_type::eof());
- return *this;
- }
-
- ostreambuf_iterator& operator*() { return *this; }
- ostreambuf_iterator& operator++() { return *this; }
- ostreambuf_iterator& operator++(int) { return *this; }
-
- bool failed() const { return !_M_ok; }
-
-private:
- streambuf_type* _M_buf;
- bool _M_ok;
-};
-
-#else /* __STL_USE_NEW_IOSTREAMS */
-
-template <class _Tp, class _Dist = ptrdiff_t> class istream_iterator;
-
-template <class _Tp, class _Dist>
-inline bool operator==(const istream_iterator<_Tp, _Dist>&,
- const istream_iterator<_Tp, _Dist>&);
-
-template <class _Tp, class _Dist>
-class istream_iterator {
-#ifdef __STL_TEMPLATE_FRIENDS
- template <class _T1, class _D1>
- friend bool operator==(const istream_iterator<_T1, _D1>&,
- const istream_iterator<_T1, _D1>&);
-#else /* __STL_TEMPLATE_FRIENDS */
- friend bool __STD_QUALIFIER
- operator== __STL_NULL_TMPL_ARGS (const istream_iterator&,
- const istream_iterator&);
-#endif /* __STL_TEMPLATE_FRIENDS */
-
-protected:
- istream* _M_stream;
- _Tp _M_value;
- bool _M_end_marker;
- void _M_read() {
- _M_end_marker = (*_M_stream) ? true : false;
- if (_M_end_marker) *_M_stream >> _M_value;
- _M_end_marker = (*_M_stream) ? true : false;
- }
-public:
- typedef input_iterator_tag iterator_category;
- typedef _Tp value_type;
- typedef _Dist difference_type;
- typedef const _Tp* pointer;
- typedef const _Tp& reference;
-
- istream_iterator() : _M_stream(&cin), _M_end_marker(false) {}
- istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); }
- reference operator*() const { return _M_value; }
-#ifndef __SGI_STL_NO_ARROW_OPERATOR
- pointer operator->() const { return &(operator*()); }
-#endif /* __SGI_STL_NO_ARROW_OPERATOR */
- istream_iterator<_Tp, _Dist>& operator++() {
- _M_read();
- return *this;
- }
- istream_iterator<_Tp, _Dist> operator++(int) {
- istream_iterator<_Tp, _Dist> __tmp = *this;
- _M_read();
- return __tmp;
- }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _Tp, class _Dist>
-inline input_iterator_tag
-iterator_category(const istream_iterator<_Tp, _Dist>&)
-{
- return input_iterator_tag();
-}
-
-template <class _Tp, class _Dist>
-inline _Tp*
-value_type(const istream_iterator<_Tp, _Dist>&) { return (_Tp*) 0; }
-
-template <class _Tp, class _Dist>
-inline _Dist*
-distance_type(const istream_iterator<_Tp, _Dist>&) { return (_Dist*)0; }
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-template <class _Tp, class _Distance>
-inline bool operator==(const istream_iterator<_Tp, _Distance>& __x,
- const istream_iterator<_Tp, _Distance>& __y) {
- return (__x._M_stream == __y._M_stream &&
- __x._M_end_marker == __y._M_end_marker) ||
- __x._M_end_marker == false && __y._M_end_marker == false;
-}
-
-#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
-
-template <class _Tp, class _Distance>
-inline bool operator!=(const istream_iterator<_Tp, _Distance>& __x,
- const istream_iterator<_Tp, _Distance>& __y) {
- return !(__x == __y);
-}
-
-#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
-
-template <class _Tp>
-class ostream_iterator {
-protected:
- ostream* _M_stream;
- const char* _M_string;
-public:
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
-
- ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {}
- ostream_iterator(ostream& __s, const char* __c)
- : _M_stream(&__s), _M_string(__c) {}
- ostream_iterator<_Tp>& operator=(const _Tp& __value) {
- *_M_stream << __value;
- if (_M_string) *_M_stream << _M_string;
- return *this;
- }
- ostream_iterator<_Tp>& operator*() { return *this; }
- ostream_iterator<_Tp>& operator++() { return *this; }
- ostream_iterator<_Tp>& operator++(int) { return *this; }
-};
-
-#ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
-
-template <class _Tp>
-inline output_iterator_tag
-iterator_category(const ostream_iterator<_Tp>&) {
- return output_iterator_tag();
-}
-
-#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
-
-#endif /* __STL_USE_NEW_IOSTREAMS */
-
-// This iterator adapter is 'normal' in the sense that it does not
-// change the semantics of any of the operators of its itererator
-// parameter. Its primary purpose is to convert an iterator that is
-// not a class, e.g. a pointer, into an iterator that is a class.
-// The _Container parameter exists solely so that different containers
-// using this template can instantiate different types, even if the
-// _Iterator parameter is the same.
-template<typename _Iterator, typename _Container>
-class __normal_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 _M_current;
-
-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()) { }
-
- explicit __normal_iterator(const _Iterator& __i) : _M_current(__i) { }
-
- // Allow iterator to const_iterator conversion
- template<typename _Iter>
- inline __normal_iterator(const __normal_iterator<_Iter, _Container>& __i)
- : _M_current(__i.base()) { }
-
- // Forward iterator requirements
- reference
- operator*() const { return *_M_current; }
- pointer
- operator->() const { return _M_current; }
+ // @} group iterators
+
+_GLIBCXX_END_NAMESPACE
+
+_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
+
+ // This iterator adapter is @a normal in the sense that it does not
+ // change the semantics of any of the operators of its iterator
+ // parameter. Its primary purpose is to convert an iterator that is
+ // not a class, e.g. a pointer, into an iterator that is a class.
+ // The _Container parameter exists solely so that different containers
+ // using this template can instantiate different types, even if the
+ // _Iterator parameter is the same.
+ using std::iterator_traits;
+ using std::iterator;
+ template<typename _Iterator, typename _Container>
+ class __normal_iterator
+ {
+ protected:
+ _Iterator _M_current;
+
+ typedef iterator_traits<_Iterator> __traits_type;
+
+ public:
+ typedef _Iterator iterator_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::reference reference;
+ typedef typename __traits_type::pointer pointer;
+
+ __normal_iterator() : _M_current(_Iterator()) { }
+
+ explicit
+ __normal_iterator(const _Iterator& __i) : _M_current(__i) { }
+
+ // Allow iterator to const_iterator conversion
+ template<typename _Iter>
+ __normal_iterator(const __normal_iterator<_Iter,
+ typename __enable_if<
+ (std::__are_same<_Iter, typename _Container::pointer>::__value),
+ _Container>::__type>& __i)
+ : _M_current(__i.base()) { }
+
+ // Forward iterator requirements
+ reference
+ operator*() const
+ { return *_M_current; }
+
+ pointer
+ operator->() const
+ { return _M_current; }
+
+ __normal_iterator&
+ operator++()
+ {
+ ++_M_current;
+ return *this;
+ }
+
+ __normal_iterator
+ operator++(int)
+ { return __normal_iterator(_M_current++); }
+
+ // Bidirectional iterator requirements
+ __normal_iterator&
+ operator--()
+ {
+ --_M_current;
+ return *this;
+ }
+
+ __normal_iterator
+ operator--(int)
+ { return __normal_iterator(_M_current--); }
+
+ // Random access iterator requirements
+ reference
+ operator[](const difference_type& __n) const
+ { return _M_current[__n]; }
+
+ __normal_iterator&
+ operator+=(const difference_type& __n)
+ { _M_current += __n; return *this; }
+
+ __normal_iterator
+ operator+(const difference_type& __n) const
+ { return __normal_iterator(_M_current + __n); }
+
+ __normal_iterator&
+ operator-=(const difference_type& __n)
+ { _M_current -= __n; return *this; }
+
+ __normal_iterator
+ operator-(const difference_type& __n) const
+ { return __normal_iterator(_M_current - __n); }
+
+ const _Iterator&
+ base() const
+ { return _M_current; }
+ };
+
+ // Note: In what follows, the left- and right-hand-side iterators are
+ // allowed to vary in types (conceptually in cv-qualification) so that
+ // comparison between cv-qualified and non-cv-qualified iterators be
+ // valid. However, the greedy and unfriendly operators in std::rel_ops
+ // will make overload resolution ambiguous (when in scope) if we don't
+ // provide overloads whose operands are of the same type. Can someone
+ // remind me what generic programming is about? -- Gaby
- normal_iterator_type&
- operator++() { ++_M_current; return *this; }
-
- normal_iterator_type
- operator++(int) { return __normal_iterator(_M_current++); }
-
- // Bidirectional iterator requirements
- normal_iterator_type&
- operator--() { --_M_current; return *this; }
-
- normal_iterator_type
- operator--(int) { return __normal_iterator(_M_current--); }
+ // Forward iterator requirements
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() == __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() == __rhs.base(); }
+
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() != __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() != __rhs.base(); }
// Random access iterator requirements
- reference
- operator[](const difference_type& __n) const
- { return _M_current[__n]; }
-
- normal_iterator_type&
- operator+=(const difference_type& __n)
- { _M_current += __n; return *this; }
-
- normal_iterator_type
- operator+(const difference_type& __n) const
- { return __normal_iterator(_M_current + __n); }
-
- normal_iterator_type&
- operator-=(const difference_type& __n)
- { _M_current -= __n; return *this; }
-
- normal_iterator_type
- operator-(const difference_type& __n) const
- { return __normal_iterator(_M_current - __n); }
-
- difference_type
- operator-(const normal_iterator_type& __i) const
- { return _M_current - __i._M_current; }
-
- const _Iterator&
- base() const { return _M_current; }
-};
-
-// forward iterator requirements
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return __lhs.base() == __rhs.base(); }
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return !(__lhs == __rhs); }
-
-// random access iterator requirements
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return __lhs.base() < __rhs.base(); }
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return __rhs < __lhs; }
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return !(__rhs < __lhs); }
-
-template<typename _IteratorL, typename _IteratorR, typename _Container>
-inline bool
-operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
- const __normal_iterator<_IteratorR, _Container>& __rhs)
-{ return !(__lhs < __rhs); }
-
-template<typename _Iterator, typename _Container>
-inline __normal_iterator<_Iterator, _Container>
-operator+(__normal_iterator<_Iterator, _Container>::difference_type __n,
- const __normal_iterator<_Iterator, _Container>& __i)
-{ return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
-
-__STL_END_NAMESPACE
-
-#endif /* __SGI_STL_INTERNAL_ITERATOR_H */
-
-// Local Variables:
-// mode:C++
-// End:
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() < __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() < __rhs.base(); }
+
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() > __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() > __rhs.base(); }
+
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() <= __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() <= __rhs.base(); }
+
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+ inline bool
+ operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ { return __lhs.base() >= __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline bool
+ operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() >= __rhs.base(); }
+
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // According to the resolution of DR179 not only the various comparison
+ // operators but also operator- must accept mixed iterator/const_iterator
+ // parameters.
+ template<typename _IteratorL, typename _IteratorR, typename _Container>
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ // DR 685.
+ inline auto
+ operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+ -> decltype(__lhs.base() - __rhs.base())
+#else
+ inline typename __normal_iterator<_IteratorL, _Container>::difference_type
+ operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
+ const __normal_iterator<_IteratorR, _Container>& __rhs)
+#endif
+ { return __lhs.base() - __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline typename __normal_iterator<_Iterator, _Container>::difference_type
+ operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
+ const __normal_iterator<_Iterator, _Container>& __rhs)
+ { return __lhs.base() - __rhs.base(); }
+
+ template<typename _Iterator, typename _Container>
+ inline __normal_iterator<_Iterator, _Container>
+ operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
+ __n, const __normal_iterator<_Iterator, _Container>& __i)
+ { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
+
+_GLIBCXX_END_NAMESPACE
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+ /**
+ * @addtogroup iterators
+ * @{
+ */
+
+ // 24.4.3 Move iterators
+ /**
+ * Class template move_iterator is an iterator adapter with the same
+ * behavior as the underlying iterator except that its dereference
+ * operator implicitly converts the value returned by the underlying
+ * iterator's dereference operator to an rvalue reference. Some
+ * generic algorithms can be called with move iterators to replace
+ * copying with moving.
+ */
+ template<typename _Iterator>
+ class move_iterator
+ {
+ protected:
+ _Iterator _M_current;
+
+ typedef iterator_traits<_Iterator> __traits_type;
+
+ public:
+ typedef _Iterator iterator_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;
+ // NB: DR 680.
+ typedef _Iterator pointer;
+ typedef value_type&& reference;
+
+ move_iterator()
+ : _M_current() { }
+
+ explicit
+ move_iterator(iterator_type __i)
+ : _M_current(__i) { }
+
+ template<typename _Iter>
+ move_iterator(const move_iterator<_Iter>& __i)
+ : _M_current(__i.base()) { }
+
+ iterator_type
+ base() const
+ { return _M_current; }
+
+ reference
+ operator*() const
+ { return std::move(*_M_current); }
+
+ pointer
+ operator->() const
+ { return _M_current; }
+
+ move_iterator&
+ operator++()
+ {
+ ++_M_current;
+ return *this;
+ }
+
+ move_iterator
+ operator++(int)
+ {
+ move_iterator __tmp = *this;
+ ++_M_current;
+ return __tmp;
+ }
+
+ move_iterator&
+ operator--()
+ {
+ --_M_current;
+ return *this;
+ }
+
+ move_iterator
+ operator--(int)
+ {
+ move_iterator __tmp = *this;
+ --_M_current;
+ return __tmp;
+ }
+
+ move_iterator
+ operator+(difference_type __n) const
+ { return move_iterator(_M_current + __n); }
+
+ move_iterator&
+ operator+=(difference_type __n)
+ {
+ _M_current += __n;
+ return *this;
+ }
+
+ move_iterator
+ operator-(difference_type __n) const
+ { return move_iterator(_M_current - __n); }
+
+ move_iterator&
+ operator-=(difference_type __n)
+ {
+ _M_current -= __n;
+ return *this;
+ }
+
+ reference
+ operator[](difference_type __n) const
+ { return std::move(_M_current[__n]); }
+ };
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator==(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return __x.base() == __y.base(); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator!=(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return !(__x == __y); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator<(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return __x.base() < __y.base(); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator<=(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return !(__y < __x); }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator>(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return __y < __x; }
+
+ template<typename _IteratorL, typename _IteratorR>
+ inline bool
+ operator>=(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ { return !(__x < __y); }
+
+ // DR 685.
+ template<typename _IteratorL, typename _IteratorR>
+ inline auto
+ operator-(const move_iterator<_IteratorL>& __x,
+ const move_iterator<_IteratorR>& __y)
+ -> decltype(__x.base() - __y.base())
+ { return __x.base() - __y.base(); }
+
+ template<typename _Iterator>
+ inline move_iterator<_Iterator>
+ operator+(typename move_iterator<_Iterator>::difference_type __n,
+ const move_iterator<_Iterator>& __x)
+ { return __x + __n; }
+
+ template<typename _Iterator>
+ inline move_iterator<_Iterator>
+ make_move_iterator(const _Iterator& __i)
+ { return move_iterator<_Iterator>(__i); }
+
+ // @} group iterators
+
+_GLIBCXX_END_NAMESPACE
+
+#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) std::make_move_iterator(_Iter)
+#else
+#define _GLIBCXX_MAKE_MOVE_ITERATOR(_Iter) (_Iter)
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
+#endif