std::remove
Актуально для C++23.
#include <algorithm>
Актуально на 2024-03-23.
Define overload #1
template<class ForwardIter, class T>
constexpr ForwardIter
remove(ForwardIter first, ForwardIter last, const T& value);
template<class ForwardIter, class T>
constexpr ForwardIter
remove(ForwardIter first, ForwardIter last, const T& value);
template<class ForwardIter, class T> constexpr ForwardIter remove(ForwardIter first, ForwardIter last, const T& value);
Удаляет элементы из диапазона [first, last] эквивалентные "value".
Удалённые элементы замещаются с помощью операции перемещения.
Эквивалентность проверяется с помощью оператора "==".
Алгоритм стабилен, т.е. порядок элементов остаётся прежним.
Тип *first должен соответствовать Cpp17MoveAssignable требованиям.
Вернёт итератор на конец результирующего диапазона.
Example, possible implementation
Define overload #2
template<class ExecutionPolicy, class ForwardIter, class T>
ForwardIter
remove(ExecutionPolicy&& exec, ForwardIter first,
ForwardIter last, const T& value);
template<class ExecutionPolicy, class ForwardIter, class T>
ForwardIter
remove(ExecutionPolicy&& exec, ForwardIter first,
ForwardIter last, const T& value);
template<class ExecutionPolicy, class ForwardIter, class T>
ForwardIter
remove(ExecutionPolicy&& exec, ForwardIter first,
ForwardIter last, const T& value);
TODO
Example, possible implementation
Examples
Example 1:
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v{1,2,3,4,5};
const auto new_end = std::remove(std::begin(v),
std::end(v),
[](auto v) { return v == 1; });
v.erase(new_end, std::end(v));
for (auto it : v)
std::cout << it << std::endl;
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v{1,2,3,4,5};
const auto new_end = std::remove(std::begin(v),
std::end(v),
[](auto v) { return v == 1; });
v.erase(new_end, std::end(v));
for (auto it : v)
std::cout << it << std::endl;
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> v{1,2,3,4,5};
const auto new_end = std::remove(std::begin(v),
std::end(v),
[](auto v) { return v == 1; });
v.erase(new_end, std::end(v));
for (auto it : v)
std::cout << it << std::endl;
return 0;
}
2
3
4
5
2
3
4
5
2 3 4 5
Changelog
See also
TODO
This page was last modified on 2024-03-23