Repository navigation
Conversation
There is no guarantee on ordering of std::multimap::find https://en.cppreference.com/cpp/container/multimap/find: > If there are several elements with the requested key in the container, > any of them may be returned.
Member
peternewman
reviewed
Sep 21, 2026
peternewman
left a comment
Member
There was a problem hiding this comment.
I was a bit worried about ordering requirements for lower_bound, but it seems like that doesn't apply to multimap just other containers. Should we also check for upper_bound to be more efficient (potentially).
If it's insertion order, then:
a=1
b=0
a=5
c=42
d=11
We could avoid inspecting c or d presumably if we stop at the upper_bound of a?
It would definitely be good to add a slightly more complex test to cover that if so.
aroffringa
reviewed
Oct 13, 2026
Comment on lines
+349
to
351
| for (iter = m_pref_map.lower_bound(key); | ||
| iter != m_pref_map.end() && iter->first == key; ++iter) { | ||
| values.push_back(iter->second); |
Contributor
There was a problem hiding this comment.
Suggested change
| for (iter = m_pref_map.lower_bound(key); | |
| iter != m_pref_map.end() && iter->first == key; ++iter) { | |
| values.push_back(iter->second); | |
| const std::pair<PreferencesMap::const_iterator, PreferencesMap::const_iterator> range = m_pref_map.equal_range(key); | |
| for (iter = range.first; iter != range.second; ++iter) { | |
| values.push_back(iter->second); |
Contributor
This is what equal_range() is for, which finds lower and upper bounds at once ; I've added a suggestion how to change that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is no guarantee on ordering of std::multimap::find https://en.cppreference.com/cpp/container/multimap/find:
In recent LLVM / Apple Clang, the PreferencesTest fails as LLVM changed their implementation so the assumption of exact returned element is no longer true:
Instead, switch to an interface that provides ordering guarantee.