aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2002-07-07 12:15:06 +0200
committerPaolo Carlini <paolo@gcc.gnu.org>2002-07-07 10:15:06 +0000
commit276e31ec6eadb5318f9a826f36642a324668d796 (patch)
tree121a8bcacd0f5614814348a2faf67819fe426ae8
parent12f2f485a335fadb2d444b134e2eb0d795945e25 (diff)
downloadgcc-276e31ec6eadb5318f9a826f36642a324668d796.zip
gcc-276e31ec6eadb5318f9a826f36642a324668d796.tar.gz
gcc-276e31ec6eadb5318f9a826f36642a324668d796.tar.bz2
re PR libstdc++/7186 (DR179 for std::deque::iterator and const_iterator)
2002-07-07 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/7186 * include/bits/stl_deque.h (_Deque_iterator::operator-): Make non-member, as already happens for the comparison operators in accord with DR179 (Ready). * testsuite/23_containers/deque_operators.cc: Add test02. From-SVN: r55301
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/stl_deque.h21
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque_operators.cc22
3 files changed, 46 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 90d0eb7..874d673 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2002-07-07 Paolo Carlini <pcarlini@unitus.it>
+
+ PR libstdc++/7186
+ * include/bits/stl_deque.h (_Deque_iterator::operator-):
+ Make non-member, as already happens for the comparison
+ operators in accord with DR179 (Ready).
+ * testsuite/23_containers/deque_operators.cc: Add test02.
+
2002-07-04 Benjamin Kosnik <bkoz@redhat.com>
Jack Reeves <jackw_reeves@hotmail.com>
diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h
index 1eedc6a..cbf8ad3 100644
--- a/libstdc++-v3/include/bits/stl_deque.h
+++ b/libstdc++-v3/include/bits/stl_deque.h
@@ -132,11 +132,6 @@ template <typename _Tp, typename _Ref, typename _Ptr>
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) {
@@ -318,6 +313,22 @@ operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
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 <typename _Tp, typename _Ref, typename _Ptr>
inline _Deque_iterator<_Tp, _Ref, _Ptr>
operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
diff --git a/libstdc++-v3/testsuite/23_containers/deque_operators.cc b/libstdc++-v3/testsuite/23_containers/deque_operators.cc
index 9585514..5463b47 100644
--- a/libstdc++-v3/testsuite/23_containers/deque_operators.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque_operators.cc
@@ -56,8 +56,30 @@ void test01()
VERIFY( constend <= end );
}
+// libstdc++/7186
+void test02()
+{
+ bool test = true;
+
+ std::deque<int> d(2);
+ typedef std::deque<int>::iterator iter;
+ typedef std::deque<int>::const_iterator constiter;
+
+ iter beg = d.begin();
+ iter end = d.end();
+ constiter constbeg = d.begin();
+ constiter constend = d.end();
+
+ VERIFY( beg - constbeg == 0 );
+ VERIFY( constend - end == 0 );
+
+ VERIFY( end - constbeg > 0 );
+ VERIFY( constend - beg > 0 );
+}
+
int main()
{
test01();
+ test02();
return 0;
}