Пространства имён
Варианты
Действия

std::forward_list::remove, std::forward_list::remove_if

Материал из cppreference.com

 
 
 
std::forward_list
Член функций
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::forward_list
forward_list::~forward_list
forward_list::operator=
forward_list::assign
forward_list::get_allocator
Элемент доступа
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::front
Итераторы
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::before_begin
forward_list::cbefore_begin
forward_list::begin
forward_list::cbegin
forward_list::end
forward_list::cend
Потенциала
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::empty
forward_list::max_size
Модификаторы
Original:
Modifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::clear
forward_list::insert_after
forward_list::emplace_after
forward_list::erase_after
forward_list::push_front
forward_list::emplace_front
forward_list::pop_front
forward_list::resize
forward_list::swap
Операции
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
forward_list::merge
forward_list::splice_after
forward_list::remove
forward_list::remove_if
forward_list::reverse
forward_list::unique
forward_list::sort
 
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.


Содержание

[править] Параметры

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.
.

Сигнатура функции-предиката должны быть эквивалентна следующей:

bool pred(const Type &a);

В сигнатуре не обязательно наличие const &, но функция не должна изменять переданный ей объект.
Тип Type должен быть таков, что объект типа forward_list<T,Allocator>::const_iterator может быть разыменован и затем неявно преобразован в Type. ​

[править] Возвращаемое значение

(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
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.

[править] Пример

#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.

(шаблон функции) [edit]