std::forward_list::remove, std::forward_list::remove_if
Материал из cppreference.com
< cpp | container | forward list
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| void remove( const T& value ); |
(начиная с C++11) | |
| template< class UnaryPredicate > void remove_if( UnaryPredicate p ); |
(начиная с C++11) | |
Удаляет все элементы, удовлетворяющие определенным критериям. Первая версия удаляет все элементы, которые равны
value, вторая версия удаляет все элементы, для которых предикат возвращает p true. Original:
Removes all elements satisfying specific criteria. The first version removes all elements that are equal to
value, the second version removes all elements for which predicate p returns true. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Содержание |
[править] Параметры
| value | - | Значение элементов для удаления
Original: value of the elements to remove The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| p | - | унарный предикат, который возвращает true если элемент должен быть удален . Original: if the element should be removed The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. Сигнатура функции-предиката должны быть эквивалентна следующей:
В сигнатуре не обязательно наличие const &, но функция не должна изменять переданный ей объект. | |||||||||
[править] Возвращаемое значение
(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Сложность
линейные по размеру контейнера
Original:
linear in the size of the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[править] Пример
#include <forward_list> #include <iostream> int main() { std::forward_list<int> l = { 1,100,2,3,10,1,11,-1,12 }; l.remove(1); // remove both elements equal to 1 l.remove_if([](int n){ return n > 10; }); // remove all elements greater than 10 for (int n : l) { std::cout << n << ' '; } std::cout << '\n'; }
Вывод:
2 3 10 -1
[править] См. также
| удаляет элементы, удовлетворяющие определенным критериям Original: removes elements satisfying specific criteria The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |