<flat_map>: Unify _Emplace_hint() with <flat_set> - #6435
Open
zika (tycket033-tech) wants to merge 1 commit into
Open
<flat_map>: Unify _Emplace_hint() with <flat_set>#6435zika (tycket033-tech) wants to merge 1 commit into
zika (tycket033-tech) wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The refactor preserves insertion and overwrite semantics while matching the existing flat_set implementation.
Pull request overview
Unifies flat_map::_Emplace_hint() with the established flat_set insertion pattern without changing behavior.
Changes:
- Replaces ordering classification with direct hint correction.
- Consolidates duplicate handling and insertion.
File summaries
| File | Description |
|---|---|
stl/inc/flat_map |
Refactors hinted map insertion logic. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The new unique-map backward-search path lacks direct regression coverage.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
stl/inc/flat_map:934
- The refactored unique-container backward-search path has no
flat_mapregression coverage. Existing unique-map hint tests usecbegin()with an equal or larger key, while the comprehensive hint-position test only instantiatesflat_multimap; please addflat_mapcases with a hint after the key, including duplicateinsert/try_emplaceandinsert_or_assign, to exercise thislower_boundpath and its equivalent-element handling.
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Rewrite flat_map's `_Emplace_hint()` to follow the same code pattern as flat_set's: first correct the hint towards `lower_bound(_Key_val)` (for unique containers) or the closest valid insertion position (for non-unique containers), then handle the equivalent-element case (overwriting when `_OverwriteIfExists`), and finally insert through `_Emplace_exact()`. This replaces the previous `weak_ordering` classification logic and removes a duplicated `_IsUnique` special-casing for the overwrite path. Also add flat_map regression coverage for the backward-search hint path, where the hint is positioned after the key: inserting a new key, duplicate try_emplace, duplicate insert, and insert_or_assign overwriting an existing key. Semantics are unchanged for all hint cases. Fixes microsoft#6069
zika (tycket033-tech)
force-pushed
the
issue-6069-unify-emplace-hint
branch
from
September 5, 2026 05:12
f63339c to
52907f6
Compare
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.
<flat_map>and<flat_set>had very different implementations of_Emplace_hint(); this PR unifies flat_map's version to follow flat_set's pattern.The hint is first corrected towards
lower_bound(_Key_val)(for unique containers) or the closest valid insertion position (for non-unique containers), then the equivalent-element case is handled (overwriting when_OverwriteIfExists), and the insertion goes through_Emplace_exact()as before. This replaces the previousweak_orderingclassification logic and removes a duplicated_IsUniquespecial-casing for the overwrite path, as suggested in the issue.There are no behavior changes.
Fixes #6069.