This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: multiset forward iterator is const
- To: Benjamin Kosnik <bkoz at cygnus dot com>, libstdc++ at sourceware dot cygnus dot com, 36600 at bugs dot debian dot org, Matthias Klose <doko at cs dot tu-berlin dot de>
- Subject: Re: multiset forward iterator is const
- From: David Marwood <marwood at infranetsolutions dot com>
- Date: Wed, 10 Nov 1999 12:01:10 -0800 (PST)
- References: <14377.44790.460445.176267@bolero><Pine.SUN.3.91.991110113553.28592B@rtl.cygnus.com>
Hi Benjamin. Your code compiles fine for me as well. However, in
your code, 'y' is a const reference (const T&), not a reference (T&)
as required by the spec. You can demonstrate this by compiling (or
failing to compile) the code:
#include <set>
int main(void)
{
typedef multiset<int, less<int> > multiset_type;
multiset_type x;
x.insert(5);
multiset_type::iterator iter = x.begin();
multiset_type::reference y = *iter;
y = 6;
}
[patricia:~]g++ -o test test.cpp
test.cpp: In function `int main()':
test.cpp:10: assignment of read-only reference `y'
[patricia:~]
To be more clear, multiset_type::reference and int& must be the same
type and they are not.
David Marwood
Benjamin Kosnik writes:
: > International Standard for Information Systems Programming Language
: > C++" says that the multiset must support forward iterators. A forward
: > iterator's operator* must return a reference (T&). The implementation
:
: This code, which differs from yours, compiles without warning with the
: v-3 release (which is not the same as 2.90, and is the expressed subject
: of this list.)
:
: #include <set>
:
: int main(void)
: {
: typedef multiset<int, less<int> > multiset_type;
: multiset_type x;
: x.insert(5);
: multiset_type::iterator iter = x.begin();
: multiset_type::reference y = *iter;
: }
Matthias Klose writes:
: "The Dec 2, 1996 draft of the "Working Paper for Draft Proposed
: International Standard for Information Systems Programming Language
: C++" says that the multiset must support forward iterators. A forward
: iterator's operator* must return a reference (T&). The implementation
: in libstdc++2.9-dev multiset.h returns a const reference (const T&).
: This is not correct."
:
: #include <multiset.h>
:
: int main(void)
: {
: multiset<int, less<int> > x;
: x.insert(5);
: multiset<int, less<int> >::iterator iter = x.begin();
: int& y = *iter;
: }
: [patricia:~]g++ test.cpp
: test.cpp: In function `int main(...)':
: test.cpp:8: warning: conversion from `const int' to `int &' discards const