[Unordered] size() != distance(begin(), end())
Dear all, I have an instance of boost::unordered_map<> somewhere in my codebase (GCC 4.5.1, MinGW, WinXP) with the following funny piece of test code: container_[id].insert(v); cout << "container insertion succesful" << endl; cout << "The container now contains " << container_.size() << " ids in it." << endl; cout << "distance from begin to end = " << distance(container_.begin(), container_.end()) << endl; Strangely enough, it happens sometimes that the output I get is: container insertion succesful The container now contains 2 ids in it. distance from begin to end = 1 I.e., size() != distance(begin(), end()) which is against the documentation: http://www.boost.org/doc/libs/1_44_0/doc/html/boost/unordered_map.html#id134... Am I missing anything? Or, is this a bug in the implementation of boost::unordered_map<>? TIA, --Hossein
On 13 September 2010 14:21, Hossein Haeri
I have an instance of boost::unordered_map<> somewhere in my codebase (GCC 4.5.1, MinGW, WinXP) with the following funny piece of test code:
container_[id].insert(v);
What's the full type of the unordered_map? As you seem to be inserting into the mapped value, is that right?
cout << "container insertion succesful" << endl; cout << "The container now contains " << container_.size() << " ids in it." << endl; cout << "distance from begin to end = " << distance(container_.begin(), container_.end()) << endl;
Can you try changing that to 'std::distance(container_.begin(), container_.end())' to make sure that the correct function is called.
Am I missing anything? Or, is this a bug in the implementation of boost::unordered_map<>?
It might be. Would it be possible to create a compilable demonstration of the issue? Or some more information on how you set up the container and what methods you have called? Daniel
Daniel,
container_[id].insert(v);
What's the full type of the unordered_map? As you seem to be inserting into the mapped value, is that right?
Yes. And, the full type is something like:
unordered_map
cout << "container insertion succesful" << endl; cout << "The container now contains " << container_.size() << " ids in it." << endl; cout << "distance from begin to end = " << distance(container_.begin(), container_.end()) << endl;
Can you try changing that to 'std::distance(container_.begin(), container_.end())' to make sure that the correct function is called.
A few lines earlier I had written using std::distance;
It might be. Would it be possible to create a compilable demonstration of the issue? Or some more information on how you set up the container and what methods you have called?
In fact, I realised that that was a bug in my own code. I had a shared_ptr to container_ that was trying to destruct it earlier than it should have. Having the bug fixed though, I still think that this was a strange behaviour for the container should have failed to produce anything for any of the cout's above. I'll try to see if -- without the bug there -- I can still produce a minimalist demonstration to pass over. I'll let you know... Cheers, --Hossein
participants (2)
-
Daniel James
-
Hossein Haeri