Skip to content

[flat.map.modifiers] Remove redundancy in 'insert(sorted_unique, i, j)'#8214

Merged
tkoeppe merged 1 commit into
cplusplus:mainfrom
jwakely:flat.multimap.modifiers-remove-redundancy
Oct 31, 2025
Merged

[flat.map.modifiers] Remove redundancy in 'insert(sorted_unique, i, j)'#8214
tkoeppe merged 1 commit into
cplusplus:mainfrom
jwakely:flat.multimap.modifiers-remove-redundancy

Conversation

@jwakely

@jwakely jwakely commented Sep 5, 2025

Copy link
Copy Markdown
Member

We can specify this in terms of the overload without the sorted_unique tag. That is consistent with how the equivalent functions in flat_set and flat_multiset are specified.

LWG asked for this in the telecon today.

We can specify this in terms of the overload without the `sorted_unique`
tag. That is consistent with how the equivalent functions in `flat_set`
and `flat_multiset` are specified.
@jwakely

jwakely commented Oct 31, 2025

Copy link
Copy Markdown
Member Author

To give some more context: the wording for insert(i, j) is not word-for-word identical to the wording for insert(sorted_unique, i, j) because the latter has the additional text "sorts the range of newly inserted elements with respect to value_comp();" which implies it does more work.

However, if the contents of the range [i, j) is already sorted then that step is a no-op. The implementation can elide that step, because it doesn't say the effects are equivalent to actually calling ranges::sort, it just says "sorts the range". If the implementation happens to know it's already sorted, it can skip that step.

So specifying insert(sorted_unique, i, j) in terms of insert(i, j) with a more restrictive complexity guarantee completely described the effects, and specifies the complexity.

And [flat.set.modifiers] p8 and [flat.multiset.modifiers] p7 already take exactly this specification approach, just deferring to insert(i, j) instead of duplicating 95% of its wording.

@jwakely

jwakely commented Oct 31, 2025

Copy link
Copy Markdown
Member Author

And [structure.specifications] p4 says that the Complexity: element here overrules the implied Complexity: that we would otherwise have from using "Effects: Equivalent to ..."

@tkoeppe

tkoeppe commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

Thanks for the explanations! Yes, it certainly seems technically correct, and a good deduplication. The more restrictive complexity may be a bit subtle, but then again, the Standard is not a tuturial, and implementers will know how to read this.

@tkoeppe tkoeppe merged commit 7f1926b into cplusplus:main Oct 31, 2025
2 checks passed
@jwakely jwakely deleted the flat.multimap.modifiers-remove-redundancy branch October 31, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants