hash_table iterator problems
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 (?) }
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
Sorry, I have to take back my bug report. It was not referring to the sandbox files but to the cvs version. I accidentally resurrected it. Daniel, your code works like a charm. Only the conversion from const_iterator to iterator is a little bit unexpected if you are used to the std containers. But of course it is confirming to the specifications. Can't you move your code to the official cvs? It can't be buggier than what is in there now. Thanks, Martin
Martin Wartens wrote:
Sorry, I have to take back my bug report. It was not referring to the sandbox files but to the cvs version. I accidentally resurrected it. Daniel, your code works like a charm. Only the conversion from const_iterator to iterator is a little bit unexpected if you are used to the std containers. But of course it is confirming to the specifications. Can't you move your code to the official cvs? It can't be buggier than what is in there now. Thanks, Martin
Now I'm confused, I didn't think there was a hash table implementation in cvs. Anyway, I'll add my implementation (well, the headers at least) to the sandbox cvs later today. Daniel
participants (2)
-
Daniel James
-
Martin Wartens