[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#160978: libstdc++5-dev: constness problem with std::set



On Sun, Sep 15, 2002 at 07:16:41PM +0100, Matt Kern wrote:
> Package: libstdc++5-dev
> Version: 1:3.2.1-0pre1
> Severity: normal
> 
> The following fragment generates an error for me:
> 
> ======================================================================
> #include <set>

>     for (WrappedClassList::iterator i=_objects.begin (); i!=_objects.end (); ++i)
>       WrappedClass* C = (*i).getObjectPtr ();

> test.cpp: In member function `void TestClass::testMethod()':
> test.cpp:27: invalid conversion from `const WrappedClass*' to `WrappedClass*'
> 
> I cannot work out if the bug is caused by my installing the debian
> packages on woody rather than unstable.  However, the fragment
> compiles correctly if std::vector is used in place of std::set.
> 
> If the "const T* getObjectPtr () const { return 0; }" line is removed,
> it gives the following:
> 
> test.cpp: In member function `void TestClass::testMethod()':
> test.cpp:26: passing `const AutoPtr<WrappedClass>' as `this' argument of `T*
>    AutoPtr<T>::getObjectPtr() [with T = WrappedClass]' discards qualifiers

That's because set has:

  typedef typename _Rep_type::const_iterator iterator;

i.e. set's iterators are actually const_iterators.  The STL reference
says:
 Const iterator used to iterate through a set. (Iterator and
 const_iterator are the same type.)

So I believe this isn't a bug; there are no mutable iterators to sets,
because that would disturb the invariants of set (sorted!).

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer



Reply to: