This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] libstdc++/7186


Hi,

the below, tested i686-pc-linux-gnu, and approved by Phil Edwards,
is the last in a series of three (for 6503, 6642 and 7186) implementing
the resolution of DR179 <Ready>.

Ciao, Paolo.

/////////////

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.

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_deque.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- gcc/libstdc++-v3/include/bits/stl_deque.h 2002/06/12 22:07:51 1.22
+++ gcc/libstdc++-v3/include/bits/stl_deque.h 2002/07/07 10:15:05 1.23
@@ -132,11 +132,6 @@
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) {
@@ -316,6 +311,22 @@
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 <typename _Tp, typename _Ref, typename _Ptr>

===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/23_containers/deque_operators.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- gcc/libstdc++-v3/testsuite/23_containers/deque_operators.cc 2002/05/19 09:16:21 1.2
+++ gcc/libstdc++-v3/testsuite/23_containers/deque_operators.cc 2002/07/07 10:15:06 1.3
@@ -56,8 +56,30 @@
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;
}







Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]