Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-972

std::vector<bool>::iterator doesn't meet random iterator requirements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.1.2, 4.1.3, 4.1.4, 4.2.0, 4.2.1
    • 4.2.2
    • 23. Containers
    • 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 
      

      Attachments

        Activity

          People

            farid Farid Zaripov
            farid Farid Zaripov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified