【发布时间】:2018-06-05 11:14:34
【问题描述】:
我想在将 std::map 转换为 std::list 时节省 RAM。因此,我必须删除其间的每个元素。但我得到了一个 SIGSEGV。
template <class U>
auto ConvertFlatSegmentsMapToList(std::map<std::string /* relative_path */, U>& differences_map, std::list<U>& differences_list) -> void {
for (auto& i:differences_map) {
differences_list.push_back(i.second);
// differences_map.erase(i.first);//TODO: SIGSEGV
}
}
怎么做?
【问题讨论】:
-
当我在 for 循环后清除时,我不保存 RAM。我希望我一个一个地复制并在其间删除以节省 RAM。
-
这应该有助于您在迭代时删除:stackoverflow.com/a/8234813/1142788
-
@yussuf:谢谢。我添加了一个答案。
标签: c++ stdmap segmentation-fault stdlist