无法在std::set上使用set_intersection
unable to use set_intersection on std::set
我试图使用set_intersection如下所述
std::set<std::pair<char*, int>,FileLinePairComapare > netSet;
std::set<std::pair<char*, int>,FileLinePairComapare > portSet;
std::set<std::pair<char*, int>,FileLinePairComapare> result;
std::set<std::pair<char*, int>,FileLinePairComapare>::iterator it;
std::set_intersection(netSet.begin(),netSet.end(),portSet.begin(),portSet.end(),result.begin());
我在最后一行得到编译错误
在实例化' _OIter ' std::set_intersection(_IIter1, _IIter1,_IIter2, _IIter2, _OIter) [with _IIter1 = std::_Rb_tree_const_iterator>;_IIter2 =std:: _Rb_tree_const_iterator>;_OIter =std:: _Rb_tree_const_iterator>]:
传递' const std::pair '作为' this '参数"std:: pair&一对std::::操作符= (constStd::pair&) '放弃限定符[-fpermissive]
没有cons函数,我使用这些集合和set_intersection
不能使用算法直接写入std::set
迭代器。所有 set迭代器都是const,因为改变任何值都会破坏树(同样适用于std::map
键- map迭代器只能修改映射的值)。
即使你可以,它也不会工作,因为容器是空的(例如,如果你试图使用std::vector
作为目标容器,你最终会有未定义的行为)。
使用std::inserter
std::set_intersection(
netSet.begin(), netSet.end(),
portSet.begin(), portSet.end(),
std::inserter(result, result.end())
);
相关文章:
- 为什么我无法更改"set<set>"循环中的值<int>
- 对于set上的循环-获取next元素迭代器
- 在声明中合并两个常量"std::set"(不是在运行时)
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将 std::set 与基于键的比较器一起使用
- 如何使用set实现无序数据结构?
- 使用运算符调用 void 函数时出错<set>
- 修改"std::set"中用户定义类型的值
- 生成提升::hana::set 的常量表达式问题
- 如何在构造函数参数中初始化"std::set"?
- 如何使用 lower_bound/upper_bound 从 std::set 获取索引号?
- 如何在 C++ 中转发声明 std::set?
- 重构使用动态强制转换的 std::set 的比较运算符
- set::find 查找不存在的元素
- 为什么 std::set.erase(first, last) 会影响从中获取 (first, last) 的容器?
- 将 std:set<int32_t> 复制到 std::set <uint32_t>的好方法
- 错误 C2676:std::set::const_iterator 没有运算符 + 函数?
- std::set 是否将对象连续存储在内存中?
- 是否有一个 std::set 函数来确定不超过数字 x 的最大元素?
- google test PrintTo for std::set<std::string>