Error in stl?

Anders Fugmann afu@fugmann.net
Thu Aug 19 14:50:00 GMT 2004


Hi,

It seems that there is an error in the STL implementation in gcc version
3.3, 3.4 and 3.5, as it cannot compile when using 
const_reverse_iterators to iterate over a simple vector.

The following code exposes the problem:

===========
#include <vector>

void test()
{
   std::vector<int> v;
   int sum = 0;
   // This works as expected.
   for (std::vector<int>::const_iterator i = v.begin();
        i != v.end(); ++i) {
     sum += *i;
   }

   // This also works.
   for (std::vector<int>::reverse_iterator i = v.rbegin();
        i != v.rend(); ++i) {
     sum += *i;
   }

   // This cannot compile.
   for (std::vector<int>::const_reverse_iterator i = v.rbegin();
        i != v.rend(); ++i) {
     sum += *i;
   }
}
===============

When trying to compile the above, I get the error:

test.cc:18: error: no match for 'operator!=' in 'i != std::vector<_Tp,
    _Alloc>::rend() [with _Tp = int, _Alloc = std::allocator<int>]()'

(is the const version of rend() missing?)

Should I file a report in bugzilla, or am i misinterpreting the c++ 
programming language?

Regards
Anders Fugmann



More information about the Gcc mailing list