From b2536b7c3de5aaaa18a5205a851d43059f868c57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Thu, 9 May 2019 05:28:42 +0000 Subject: [PATCH] stl_deque.h (operator==(const _Deque_iterator<>&, const _Deque_iterator<>&)): Make hidden friend. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2019-05-09 François Dumont * include/bits/stl_deque.h (operator==(const _Deque_iterator<>&, const _Deque_iterator<>&)): Make hidden friend. (operator!=(const _Deque_iterator<>&, const _Deque_iterator<>&)): Likewise. (operator<(const _Deque_iterator<>&, const _Deque_iterator<>&)): Likewise. (operator<=(const _Deque_iterator<>&, const _Deque_iterator<>&)): Likewise. (operator>(const _Deque_iterator<>&, const _Deque_iterator<>&)): Likewise. (operator>=(const _Deque_iterator<>&, const _Deque_iterator<>&)): Likewise. (_Deque_iterator<>::operator+(difference_type)): Likewise and allow NRVO copy elision. (_Deque_iterator<>::operator-(difference_type)): Likewise. From-SVN: r271027 --- libstdc++-v3/ChangeLog | 19 ++ libstdc++-v3/include/bits/stl_deque.h | 247 ++++++++++++-------------- 2 files changed, 130 insertions(+), 136 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 15ac9fb913a..f8344812ba5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2019-05-09 François Dumont + + * include/bits/stl_deque.h + (operator==(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Make hidden friend. + (operator!=(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Likewise. + (operator<(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Likewise. + (operator<=(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Likewise. + (operator>(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Likewise. + (operator>=(const _Deque_iterator<>&, const _Deque_iterator<>&)): + Likewise. + (_Deque_iterator<>::operator+(difference_type)): Likewise and allow NRVO + copy elision. + (_Deque_iterator<>::operator-(difference_type)): Likewise. + 2019-05-08 François Dumont PR libstdc++/90277 diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 5c86efc0db2..6e0f6dcd784 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -239,24 +239,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } - _Self - operator+(difference_type __n) const _GLIBCXX_NOEXCEPT - { - _Self __tmp = *this; - return __tmp += __n; - } - _Self& operator-=(difference_type __n) _GLIBCXX_NOEXCEPT { return *this += -__n; } - _Self - operator-(difference_type __n) const _GLIBCXX_NOEXCEPT - { - _Self __tmp = *this; - return __tmp -= __n; - } - reference operator[](difference_type __n) const _GLIBCXX_NOEXCEPT { return *(*this + __n); } @@ -273,123 +259,118 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_first = *__new_node; _M_last = _M_first + difference_type(_S_buffer_size()); } - }; - - // Note: we also provide overloads whose operands are of the same type in - // order to avoid ambiguous overload resolution when std::rel_ops operators - // are in scope (for additional details, see libstdc++/3628) - template - inline bool - operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return __x._M_cur == __y._M_cur; } - - template - inline bool - operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return __x._M_cur == __y._M_cur; } - - template - inline bool - operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return !(__x == __y); } - - template - inline bool - operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return !(__x == __y); } - - template - inline bool - operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur) - : (__x._M_node < __y._M_node); } - template - inline bool - operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur) - : (__x._M_node < __y._M_node); } - - template - inline bool - operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return __y < __x; } - - template - inline bool - operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return __y < __x; } - - template - inline bool - operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return !(__y < __x); } + friend bool + operator==(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { return __x._M_cur == __y._M_cur; } + + // Note: we also provide overloads whose operands are of the same type in + // order to avoid ambiguous overload resolution when std::rel_ops operators + // are in scope (for additional details, see libstdc++/3628) + template + friend bool + operator==(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { return __x._M_cur == __y._M_cur; } + + friend bool + operator!=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { return !(__x == __y); } + + template + friend bool + operator!=(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { return !(__x == __y); } + + friend bool + operator<(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { + return (__x._M_node == __y._M_node) + ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); + } - template - inline bool - operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return !(__y < __x); } + template + friend bool + operator<(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { + return (__x._M_node == __y._M_node) + ? (__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node); + } - template - inline bool - operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { return !(__x < __y); } + friend bool + operator>(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { return __y < __x; } + + template + friend bool + operator>(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { return __y < __x; } + + friend bool + operator<=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { return !(__y < __x); } + + template + friend bool + operator<=(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { return !(__y < __x); } + + friend bool + operator>=(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { return !(__x < __y); } + + template + friend bool + operator>=(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { return !(__x < __y); } + + friend difference_type + operator-(const _Self& __x, const _Self& __y) _GLIBCXX_NOEXCEPT + { + return difference_type(_S_buffer_size()) + * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + + (__y._M_last - __y._M_cur); + } - template - inline bool - operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { return !(__x < __y); } + // _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 + friend difference_type + operator-(const _Self& __x, + const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT + { + return difference_type(_S_buffer_size()) + * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + + (__y._M_last - __y._M_cur); + } - // _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 - inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type - operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, - const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) _GLIBCXX_NOEXCEPT - { - return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type - (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size()) - * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) - + (__y._M_last - __y._M_cur); - } + friend _Self + operator+(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT + { + _Self __tmp = __x; + __tmp += __n; + return __tmp; + } - template - inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type - operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, - const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) _GLIBCXX_NOEXCEPT - { - return typename _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); - } + friend _Self + operator-(const _Self& __x, difference_type __n) _GLIBCXX_NOEXCEPT + { + _Self __tmp = __x; + __tmp -= __n; + return __tmp; + } - template - inline _Deque_iterator<_Tp, _Ref, _Ptr> - operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) - _GLIBCXX_NOEXCEPT - { return __x + __n; } + friend _Self + operator+(difference_type __n, const _Self& __x) _GLIBCXX_NOEXCEPT + { return __x + __n; } + }; template void @@ -2306,8 +2287,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ template inline bool - operator==(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator==(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); } @@ -2324,37 +2304,32 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER */ template inline bool - operator<(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator<(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } /// Based on operator== template inline bool - operator!=(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator!=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template inline bool - operator>(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template inline bool - operator<=(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator<=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template inline bool - operator>=(const deque<_Tp, _Alloc>& __x, - const deque<_Tp, _Alloc>& __y) + operator>=(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) { return !(__x < __y); } /// See std::deque::swap(). -- 2.30.2