473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

operator != for const_reverse_iterator

Hello everyone,

Could someone please confirm that the following program is valid:

#include <list>
typedef std::list<intList;
int main()
{
List foo;
foo.push_back(1);
foo.push_back(2);
int accu = 0;
List::const_reverse_iterator it;
for (it = foo.rbegin(); it != foo.rend(); ++it) accu += *it;
return accu;
}

$ g++ -std=c++98 -Wall -Wextra mini.cxx
mini.cxx: In function `int main()':
mini.cxx:10: error: no match for 'operator!=' in 'it != std::list<_Tp,
_Alloc>::rend() [with _Tp = int, _Alloc = std::allocator<int>]()'

AFAIU, this is a compiler bug.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11729

I suppose my version of GCC is starting to show its age.
(3.4.4 was released on 2005-05-18.)
However 3.4.6 (released on 2006-03-06) produces the same error.

I suppose that the appropriate work around is to change
const_reverse_iterator to reverse_iterator?

Regards.
Mar 23 '07 #1
1 3657
"Spoon" <de*****@localhost.comwrote in message
news:46***********************@news.free.fr...
: Hello everyone,
:
: Could someone please confirm that the following program is valid:
:
: #include <list>
: typedef std::list<intList;
: int main()
: {
: List foo;
: foo.push_back(1);
: foo.push_back(2);
: int accu = 0;
: List::const_reverse_iterator it;
: for (it = foo.rbegin(); it != foo.rend(); ++it) accu += *it;
: return accu;
: }
:
: $ g++ -std=c++98 -Wall -Wextra mini.cxx
: mini.cxx: In function `int main()':
: mini.cxx:10: error: no match for 'operator!=' in 'it != std::list<_Tp,
: _Alloc>::rend() [with _Tp = int, _Alloc = std::allocator<int>]()'
:
: AFAIU, this is a compiler bug.
: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11729

I am not sure if the standard specifies that operators must
allow comparison between const_ and non-const iterators.
The code does compile in VS2005, though not with Comeau.

In any case, it is more likely to be a bug in the Library,
rather than in the compiler.

: I suppose my version of GCC is starting to show its age.
: (3.4.4 was released on 2005-05-18.)
: However 3.4.6 (released on 2006-03-06) produces the same error.
:
: I suppose that the appropriate work around is to change
: const_reverse_iterator to reverse_iterator?
This will do.
Or you can use a const reference to the list, or a utility
function such as:
template<typename TT const& cst(T& p) { return p; }
leading to:
for (it = foo.rbegin(); it != cst(foo).rend(); ++it)

Note that the standard library containers in C++0x are expected
to include new member functions: cbegin(), crend() etc that
always return const_ versions of the iterators.
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Mar 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
1
by: joesoap | last post by:
Hi can anybody please tell me what is wrong with my ostream operator??? this is the output i get using the 3 attached files. this is the output after i run assignment2 -joesoap #include...
8
by: Alexander Stippler | last post by:
Hello, the standard requires a type reverse_iterator. But in the form it is required and implemented for all compilers I know, there is IMO something missing, which is essential for its usage....
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
2
by: Serengeti | last post by:
hello, I've had some hard time trying to understand why does this code compile: http://cpp.sourceforge.net/?show=10151 (*) while this doesn't: http://cpp.sourceforge.net/?show=10150 (**) Any...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
3
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
20
by: Jess | last post by:
Hello, I think the two reverse_iterators are the same, except that the const_ version doesn't allow me to change the value pointed to by the iterators. However, I have a program that works for...
3
by: eiji.anonremail | last post by:
Hi folks, I have a compile problem on linux, and maybe someone has an idea: #include <map> #include <iostream>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.