c++ - splice alternative - 从列表中移动元素而不从原始列表中删除它们

标签 c++

我想将一个列表与另一个列表合并到另一个列表中。目前我使用这个:

v_unique_sorted_list = v_list;
v_unique_sorted_list.splice(v_unique_sorted_list.end(), u_list);
v_unique_sorted_list.sort();
v_unique_sorted_list.unique();

我想要相同但不从 u_list 中删除元素。是否有替代方案,或者我必须使用循环和 insert

最佳答案

使用the 4th std::list::insert overload这将为你做循环,它不会影响u_list:

v_unique_sorted_list.insert(v_unique_sorted_list.end(),
                            u_list.begin(), u_list.end());

关于c++ - splice alternative - 从列表中移动元素而不从原始列表中删除它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35438344/

相关文章:

C++ 不要进入我的cin

c++ - QT中如何将变量从一个线程共享到多个线程

c++ 整数的幂,模板元编程

c++ - 当我 try catch [this] 时,用于回调函数的 lambda 表达式失败,为什么?

c++ - _getch 返回笑脸

c++ - 用于开发 GUI 库的文章

c++ - 尝试解码不在 base64 字符集中的值

c++ - 使用 g++ 编译 C++ 源代码时的 VLA

c++ - 成员类模板的类模板实参推导

c++ - gcc 编译错误 "binding ‘const s’ 到类型 ‘s&’ 的引用丢弃限定符“在其他容器中使用 boost::container::static_vector 时