std::ranges::remove
C++20 引入的算法,用于从范围中移除满足特定条件的元素。它是标准库算法 std::remove 的范围化版本,结合了范围库的便利性。以下是详细说明和示例:
功能
- 作用:将范围中不满足条件的元素移动到范围前部,并返回新的逻辑结尾迭代器。
- 特点:
- 不真正删除元素,仅通过移动元素实现“逻辑移除”。
- 实际需配合容器的
erase方法完成物理删除。
- 复杂度:线性复杂度 O(n),n 为范围大小。
原型
| template< std::permutable I, std::sentinel_for<I> S, class T, class Proj = std::identity > |
(since C++20) (until C++26) |
|
| template< std::permutable I, std::sentinel_for<I> S, class Proj = std::identity, |
(since C++26) | |
| (2) | ||
| template< ranges::forward_range R, class T, class Proj = std::identity > |
(since C++20) (until C++26) |
|
| template< ranges::forward_range R, class Proj = std::identity, |


526

被折叠的 条评论
为什么被折叠?



