Date: Sun, 14 Sep 2025 19:41:56 +0300
On 9/14/25 16:51, Peter Neiss via Std-Proposals wrote:
> The std::set_intersection algorithm forbids overlap of the input ranges
> with the output range, but if first1 or first2 and result would be
> equal, the algorithm could still work(see cppreference for possible
> implementation).
> This would allow inplace execution without memory allocation, which is a
> big plus.
>
> 26.8.7.4 set_intersection (wording)
>
> replace: The resulting range does not overlap with either of the
> original ranges. <https://eel.is/c++draft/set.intersection#2.sentence-2>
> with: result may be equal to first1 or first2, otherwise the resulting
> range does not overlap with either of the original ranges.
>
>
> PS: I am quite sure my statement is correct and I am not making a fool
> out of myself. Still confirmation of my claim would be great.
If the input ranges overlap, the output can generally only coincide with
the first range (the source for the copy). Otherwise you can get wrong
results with a weak comparator. It might be a better idea to have a
separate "inplace" version, that could move matching elements instead of
copying them, and avoid moving elements into themselves. Ditto for
set_difference().
> The std::set_intersection algorithm forbids overlap of the input ranges
> with the output range, but if first1 or first2 and result would be
> equal, the algorithm could still work(see cppreference for possible
> implementation).
> This would allow inplace execution without memory allocation, which is a
> big plus.
>
> 26.8.7.4 set_intersection (wording)
>
> replace: The resulting range does not overlap with either of the
> original ranges. <https://eel.is/c++draft/set.intersection#2.sentence-2>
> with: result may be equal to first1 or first2, otherwise the resulting
> range does not overlap with either of the original ranges.
>
>
> PS: I am quite sure my statement is correct and I am not making a fool
> out of myself. Still confirmation of my claim would be great.
If the input ranges overlap, the output can generally only coincide with
the first range (the source for the copy). Otherwise you can get wrong
results with a weak comparator. It might be a better idea to have a
separate "inplace" version, that could move matching elements instead of
copying them, and avoid moving elements into themselves. Ditto for
set_difference().
Received on 2025-09-14 16:42:08