std::merge
preserves order of equal elements in its input lists. Does it guarantee that elements from the first list come before equal elements from the second list, or does that guarantee only apply to equal elements within a single input list?
Example:
List1 has 1 element, A
.
List2 has 1 element, B
.
Comparator considers A
and B
to be equal.
If I std::merge(list1.begin(), list1.end(), list2.begin(), list2.end(), out, comparator)
, is the relative order of A
and B
in the output defined?
My opinion is the standard does not define order in this case.
C++14 standard draft (n3797):
17.6.5.7/1
When the requirements for an algorithm state that it is “stable” without further elaboration, it means:
— For the merge algorithms, for equivalent elements in the original two ranges, the elements from the first range (preserving their original order) precede the elements from the second range (preserving their original order).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With