diff options
Diffstat (limited to 'contrib/libstdc++/include/bits/stl_deque.h')
-rw-r--r-- | contrib/libstdc++/include/bits/stl_deque.h | 132 |
1 files changed, 117 insertions, 15 deletions
diff --git a/contrib/libstdc++/include/bits/stl_deque.h b/contrib/libstdc++/include/bits/stl_deque.h index 5fa8d125e756..ce6be7e4ce2f 100644 --- a/contrib/libstdc++/include/bits/stl_deque.h +++ b/contrib/libstdc++/include/bits/stl_deque.h @@ -130,11 +130,6 @@ struct _Deque_iterator reference operator*() const { return *_M_cur; } pointer operator->() const { return _M_cur; } - difference_type operator-(const _Self& __x) const { - return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) + - (_M_cur - _M_first) + (__x._M_last - __x._M_cur); - } - _Self& operator++() { ++_M_cur; if (_M_cur == _M_last) { @@ -194,16 +189,6 @@ struct _Deque_iterator reference operator[](difference_type __n) const { return *(*this + __n); } - bool operator==(const _Self& __x) const { return _M_cur == __x._M_cur; } - bool operator!=(const _Self& __x) const { return !(*this == __x); } - bool operator<(const _Self& __x) const { - return (_M_node == __x._M_node) ? - (_M_cur < __x._M_cur) : (_M_node < __x._M_node); - } - bool operator>(const _Self& __x) const { return __x < *this; } - bool operator<=(const _Self& __x) const { return !(__x < *this); } - bool operator>=(const _Self& __x) const { return !(*this < __x); } - /** @if maint * Prepares to traverse new_node. Sets everything except _M_cur, which * should therefore be set by the caller immediately afterwards, based on @@ -217,6 +202,123 @@ struct _Deque_iterator } }; +// Note: we also provide overloads whose operands are of the same type in +// order to avoid ambiguos overload resolution when std::rel_ops operators +// are in scope (for additional details, see libstdc++/3628) +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return __x._M_cur == __y._M_cur; +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return __x._M_cur == __y._M_cur; +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__x == __y); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return (__x._M_node == __y._M_node) ? + (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return (__x._M_node == __y._M_node) ? + (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return __y < __x; +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__y < __x); +} + +template <class _Tp, class _Ref, class _Ptr> +inline bool +operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) +{ + return !(__x < __y); +} + +template <class _Tp, class _RefL, class _PtrL, class _RefR, class _PtrR> +inline bool +operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return !(__x < __y); +} + +// _GLIBCPP_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 _Tp, typename _RefL, typename _PtrL, + typename _RefR, typename _PtrR> +inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type +operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) +{ + return _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type + (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size()) * + (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + + (__y._M_last - __y._M_cur); +} + template <class _Tp, class _Ref, class _Ptr> inline _Deque_iterator<_Tp, _Ref, _Ptr> operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) |