Standard Template Library Programmer's Guide

Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This document contains reference on SGI STL implementation

Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать
See also

remove_if , remove_copy , remove_copy_if , unique , unique_copy .

remove_if

Category: algorithms

Component type: function

Prototype

template

ForwardIterator remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);

Description

Remove_if removes from the range [first, last) every element x such that pred(x) is true . That is, remove_if returns an iterator new_last such that the range [first, new_last) contains no elements for which pred is true . [1] The iterators in the range [new_last, last) are all still dereferenceable, but the elements that they point to are unspecified. Remove_if is stable, meaning that the relative order of elements that are not removed is unchanged.

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator is mutable.

• Predicate is a model of Predicate.

• ForwardIterator 's value type is convertible to Predicate 's argument type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Remove_if performs exactly last – first applications of pred .

Example

Remove all even numbers from a vector.

vector V;

V.push_back(1);

V.push_back(4);

V.push_back(2);

V.push_back(8);

V.push_back(5);

V.push_back(7);

copy(V.begin(), V.end(), ostream_iterator(cout, " "));

// The output is "1 4 2 8 5 7"

vector::iterator new_end = remove_if(V.begin(), V.end(), compose1(bind2nd(equal_to(), 0), bind2nd( modulus(), 2)));

V.erase(new_end, V.end()); [1]

copy(V.begin(), V.end(), ostream_iterator(cout, " "));

// The output is "1 5 7".

Notes

[1] The meaning of "removal" is somewhat subtle. Remove_if does not destroy any iterators, and does not change the distance between first and last . (There's no way that it could do anything of the sort.) So, for example, if V is a vector, remove_if(V.begin(), V.end(), pred) does not change V.size() : V will contain just as many elements as it did before. Remove_if returns an iterator that points to the end of the resulting range after elements have been removed from it; it follows that the elements after that iterator are of no interest, and may be discarded. If you are removing elements from a Sequence, you may simply erase them. That is, a reasonable way of removing elements from a Sequence is S.erase(remove_if(S.begin(), S.end(), pred), S.end()) .

See also

remove , remove_copy , remove_copy_if , unique , unique_copy .

remove_copy

Category: algorithms

Component type: function

Prototype

template

OutputIterator remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);

Description

Remove_copy copies elements that are not equal to value from the range [first, last) to a range beginning at result . The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as in the range [first, last) .

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

• InputIterator is a model of Input Iterator.

• OutputIterator is a model of Output Iterator.

• InputIterator 's value type is convertible to a type in OutputIterator 's set of value types.

• T is a model of Equality Comparable.

• Objects of type T can be compared for equality with objects of InputIterator 's value type.

Preconditions

• [first, last) is a valid range.

• There is enough space in the output range to store the copied values. That is, if there are n elements in [first, last) that are not equal to value , then [result, result+n) is a valid range.

• result is not an iterator in the range [first, last) .

Complexity

Linear. Exactly last – first comparisons for equality, and at most last – first assignments.

Example

Print all nonzero elements of a vector on the standard output.

vector V;

V.push_back(-2);

V.push_back(0);

V.push_back(-1);

V.push_back(0);

V.push_back(1);

V.push_back(2);

remove_copy(V.begin(), V.end(), ostream_iterator(cout, "\n"), 0);

See also

copy , remove , remove_if , remove_copy_if , unique , unique_copy .

remove_copy_if

Category: algorithms

Component type: function

Prototype

template

OutputIterator remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);

Description

Remove_copy_if copies elements from the range [first, last) to a range beginning at result , except that elements for which pred is true are not copied. The return value is the end of the resulting range. This operation is stable, meaning that the relative order of the elements that are copied is the same as in the range [first, last) .

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

• InputIterator is a model of Input Iterator.

• OutputIterator is a model of Output Iterator.

• InputIterator 's value type is convertible to a type in OutputIterator 's set of value types.

• Predicate is a model of Predicate.

• InputIterator 's value type is convertible to Predicate 's argument type.

Preconditions

• [first, last) is a valid range.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Standard Template Library Programmer's Guide»

Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Standard Template Library Programmer's Guide»

Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x