Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
-
None
-
All
-
Patch Available
-
Compiler Error
Description
The test below fails to compile.
test.cpp
#include <vector> typedef std::vector<bool> VecBool; typedef VecBool::iterator VecBoolIter; typedef VecBool::const_iterator VecBoolCIter; int main () { VecBool vb; VecBoolIter it = vb.begin (); VecBoolCIter cit = vb.begin (); 5 + it; 5 + cit; return 0; }
test.cpp(13) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolCIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(13) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolCIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(13) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolCIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(13) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolCIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(13) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolCIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(13) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolCIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(13) : error C2677: binary '+' : no global operator found which takes type 'VecBoolCIter' (or there is no acceptable conversion) test.cpp(14) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(14) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(14) : error C2784: 'std::reverse_iterator<_Iterator> std::operator +(iterator_traits<_Iterator>::difference_type,const std::reverse_iterator<_Iterator> &)' : could not deduce template argument for 'const std::reverse_iterator<_Iterator> &' from 'VecBoolIter' include/rw/_iterator.h(274) : see declaration of 'std::operator +' test.cpp(14) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(14) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(14) : error C2784: '__rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> std::operator +(_Cont::difference_type,const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &)' : could not deduce template argument for 'const __rw::__rw_debug_iter<_Container,_Iterator,_MutableIterator> &' from 'VecBoolIter' include/rw/_iterbase.h(594) : see declaration of 'std::operator +' test.cpp(14) : error C2677: binary '+' : no global operator found which takes type 'VecBoolIter' (or there is no acceptable conversion)
The proposed fix:
Index: include/vector =================================================================== --- include/vector (revision 670160) +++ include/vector (working copy) @@ -956,6 +956,11 @@ reference operator[] (difference_type __i) { return *(*this + __i); } + + friend iterator operator+ (difference_type __n, + const iterator &__x) { + return __x + __n; + } }; class const_iterator @@ -1025,6 +1030,11 @@ const_reference operator[] (difference_type __i) { return *(*this + __i); } + + friend const_iterator operator+ (difference_type __n, + const const_iterator &__x) { + return __x + __n; + } }; #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC