C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relaxing precondition on std::set_intersection algorithm

From: Ell <ell_se_at_[hidden]>
Date: Sun, 14 Sep 2025 21:43:48 +0300
On 9/14/25 21:12, Peter Neiss wrote:
> Thank you. This is a great example. I am not even sure what the correct
> set intersection definition for weak ordering should be!
> If an element is in the intersection if it there exist elements a in A
> and b in B with equiv(a,b) == true, then the answer should be {1, 2, 3, 4}
> If an element has to be "the same value" and not only equivalent, the
> answer is {2,3}
> In math we could define the intersection on "equivalence <https://
> dict.leo.org/german-english/equivalence> class <https://dict.leo.org/
> german-english/class>es[math. sic]", not helpful here i believe.
> Is it enough if we take one arbitrary represantant of "equivalence
> <https://dict.leo.org/german-english/equivalence> class <https://
> dict.leo.org/german-english/class>es[math. sic]", then {1}, {2}, {3} and
> {4} would be a valid answer.
> set_intersection might be broken for weakly ordering.


set_intersection() already specifies the specific elements to take when
there are multiple equivalent elements (basically, treat the inputs as
multisets, and take the elements from the first range in order):

https://eel.is/c++draft/set.intersection#6

Received on 2025-09-14 18:44:07