Boost logo

Boost Users :

From: Daniel James (daniel_at_[hidden])
Date: 2005-04-22 14:49:40


Martin Wartens wrote:
> Hi,
> I have got some problems with the unordered containers from the sandbox files.
> The problem is that iterator_base<T> can't be converted into iterator or
> const_iterator. I helped myself by adding
> "friend class const_iterator; friend class iterator;"
> to iterator_base and adding a constructor like "const_iterator
> (iterator_base_type i)" to const_iterator/iterator. I have no clue if this is
> could be an official solution. See sample code below to expose the problem.
> Bye, Martin
>
> typedef boost::unordered_set<int> MySet;
> {
> MySet myset;
> MySet::const_iterator citer = myset.begin();
> MySet::iterator iter = myset.begin();
> MySet::const_iterator citer2= ++citer; //doesn't work, but should (?)
> MySet::iterator iter2 = ++citer; //doesn't work, and should not work (?)
> MySet::iterator iter3 = ++iter; //doesn't work, but should (?)
> MySet::const_iterator citer3 = iter; //works, you can't do that
> //with std::containers (?)
> }

OK, the first thing to note is that MySet::iterator and
MySet::const_iterator are actually the same type at the moment. This is
because set elements have to be const so that their keys don't change.
Unless I'm mistaken, and I wouldn't rule that out ;), it is not
specified if 'MySet::iterator iter2 = ++citer' should succeed or fail.
It might be better for me to change the implementation so that it fails,
but I'm not sure.

Anyway, to deal with your problems. Which compiler are you using? Your
sample code compiles fine for me. But the version in the sandbox has
only been tested with gcc and intel. I'll try it with some other
compilers soonish.

Daniel


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net