set_union with multiset containers?(set_union 与多集容器?)
问题描述
当一个或两个输入容器是具有重复对象的多重集时,算法 std:set_union 的返回是什么?复制人会迷路吗?
What's the return of the algorithm std:set_union when one or both input containers are multisets with duplicated objects? Do dups get lost?
假设例如:
multiset<int> ms1;
ms1.insert(1);
ms1.insert(1);
ms1.insert(1);
ms1.insert(2);
ms1.insert(3);
multiset<int> ms2;
ms2.insert(1);
ms2.insert(1);
ms2.insert(2);
ms2.insert(2);
ms2.insert(4);
vector<int> v(10);
set_union( ms1.begin(), ms1.end(), ms2.begin(), ms2.end(), v.begin() );
输出会是什么?
推荐答案
来自标准,25.3.5:
From the standard, 25.3.5:
通过定义 union()
以包含每个元素的最大出现次数,intersection()
以标准方式将集合操作的语义推广到多重集合包含最小值,等等.
The semantics of the set operations are generalised to multisets in a standard way by defining
union()
to contain the maximum number of occurrences of every element,intersection()
to contain the minimum, and so on.
因此,在您的示例中,结果将是 (1,1,1,2,2,3,4,0,0,0),因为您初始化了长度为 10 的向量.
So in your example, the result will be (1,1,1,2,2,3,4,0,0,0), since you initialised the vector with length 10.
这篇关于set_union 与多集容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:set_union 与多集容器?


基础教程推荐
- C语言3个整数的数组 1970-01-01
- 明确指定任何或所有枚举数的整数值 1970-01-01
- C++:为什么结构类需要一个虚拟方法才能成为多态? 2022-10-19
- 对 STL 容器的安全并行只读访问 2022-10-25
- C语言数组 1970-01-01
- 总计将在节日礼物上花多少钱 1970-01-01
- 迭代std :: bitset中真实位的有效方法? 2022-10-18
- 向量<unique_ptr<A>>使用初始化列表 2022-10-23
- C++多态 1970-01-01
- 用指数格式表示浮点数 1970-01-01