Std :: merge and equal order of elements

std::merge maintains the order of equal elements in its input lists. Does this guarantee that elements from the first list apply to equal elements from the second list, or does it guarantee that they apply only to equal elements in the same input list?

Example:

List1 has 1 item, A List2 has 1 item, B The comparator believes that A and B are 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 given output?

My opinion is that the standard does not determine the order in this case.

+5
source share
1 answer

Standard draft version of C ++ 14 (n3797):

17.6.5.7/1

When the requirements for an algorithm claim to be "stable" without further elaboration, this means: - For merge algorithms for equivalent elements in the original two ranges, elements from the first range (keeping their original order) precede elements from the second range (keeping their original order) .

+7
source

Source: https://habr.com/ru/post/1238569/


All Articles