c++ - std::merge 和相等的元素顺序

标签 c++ c++11

std::merge 在其输入列表中保留相等元素的顺序。它是否保证第一个列表中的元素出现在第二个列表中的相等元素之前,或者该保证仅适用于单个输入列表中的相等元素?

例子:

List1 有 1 个元素,A。 List2 有 1 个元素,B。 比较器认为 AB 相等。

如果我std::merge(list1.begin(), list1.end(), list2.begin(), list2.end(), out, comparator),就是相对顺序AB 在输出中的定义?

我的意见是标准在这种情况下没有定义顺序。

最佳答案

C++14 标准草案 (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).

关于c++ - std::merge 和相等的元素顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34343619/

相关文章:

c++ - Qt,C++ : QGraphicsScene coordinates are not working

c++ - 开关/外壳内的开关/外壳

c++ - 如果从 lambda 内部调用,无法实例化使用 decltype 推断返回类型的函数模板?

c++ - std::deque 错误?

c++ - 重载虚函数并通过指向基类的指针调用派生函数

c++ - 将我的二分搜索程序改进为递归程序?

c++ - 链接器找不到 Lua 库定义

c++ - 你能从模板参数函数签名中提取类型吗

c++ - 如何使用 SFINAE 限制输入迭代器的重载

c++ - 专门对中的自定义访问器名称