Skip to content

<flat_map>: Unify _Emplace_hint() with <flat_set> - #6435

Open
zika (tycket033-tech) wants to merge 1 commit into
microsoft:mainfrom
tycket033-tech:issue-6069-unify-emplace-hint
Open

<flat_map>: Unify _Emplace_hint() with <flat_set>#6435
zika (tycket033-tech) wants to merge 1 commit into
microsoft:mainfrom
tycket033-tech:issue-6069-unify-emplace-hint

Conversation

@tycket033-tech

Copy link
Copy Markdown
Contributor

<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 previous weak_ordering classification logic and removes a duplicated _IsUnique special-casing for the overwrite path, as suggested in the issue.

There are no behavior changes.

Fixes #6069.

@tycket033-tech
zika (tycket033-tech) requested a review from a team as a code owner September 4, 2026 17:13
Copilot AI balanced review requested due to automatic review settings September 4, 2026 17:13
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Sep 4, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

Copilot AI review requested due to automatic review settings September 4, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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_map regression coverage. Existing unique-map hint tests use cbegin() with an equal or larger key, while the comprehensive hint-position test only instantiates flat_multimap; please add flat_map cases with a hint after the key, including duplicate insert/try_emplace and insert_or_assign, to exercise this lower_bound path 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
Copilot AI review requested due to automatic review settings September 5, 2026 05:12
@tycket033-tech
zika (tycket033-tech) force-pushed the issue-6069-unify-emplace-hint branch from f63339c to 52907f6 Compare September 5, 2026 05:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The refactoring preserves insertion positions and adds focused regression coverage for the affected path.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

<flat_map>, <flat_set>: Unify _Emplace_hint()

2 participants