This is the mail archive of the gcc@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]

Error in stl?


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


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