non-standard things in the gnu stl
Uwe Sassenberg
uwe@sci-d-vis.com
Thu Feb 27 13:59:00 GMT 2003
Concerns: STL
Details: std::set, std::multiset
To whom it may concern,
My name is Uwe Sassenberg at Science-D-Visions. I found out that the API
of std::set and std::multiset are not as defined in the standard.
This is not a compiler problem, everything can be fixed within the
header-file stl_set.h and stl_multiset.h. It would be fine to find out
if the problem is already being solved by the gnu people.
Could you please tell me, with whom I should get into contact?
Thank you
Uwe Sassenberg
Here is a brief description of the problem:
------------8<------------
There is no difference in the definition of std::set<T>::iterator and
std::set<T>::const_iterator. As a consequence, there is only a method
iterator begin() const;
but the Standard requires two methods
const_iterator begin() const;
iterator begin();
The same problem exists for end() as well.
If T contains two methods foo() and foo() const, only the
foo() const method can be accessed via the iterators.
------------8<------------
#include <set>
#include <iostream>
class X
{
private:
int _i;
public:
X(int i):_i(i) { }
void foo() const { std::cout << "foo() const" << std::endl; }
void foo() { std::cout << "foo()" << std::endl; }
bool operator < (const X& x) const { return _i < x._i; }
};
void test(std::set<X>& s) { s.begin()->foo(); }
void test_const(const std::set<X>& s) { s.begin()->foo(); }
int main()
{
std::set<X> s;
s.insert(X(1));
test(s);
test_const(s);
}
Compile with g++ -g test_set.C -o test_set
produces
foo() const
foo() const
but should produce
foo()
foo() const
--
S c i e n c e . D . V i s i o n s
Emil-Figge Str. 80 D-44227 Dortmund Germany
Phone: ++ 49 231 9742 188 Fax: ++ 49 231 9742 189
mailto:info@sci-d-vis.com http://www.sci-d-vis.com
More information about the Gcc-bugs
mailing list