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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

For the second (binary) version:

• [first1, last1) is a valid range.

• [first2, first2 + (last1 – first1)) is a valid range.

• result is not an iterator within the range [first1+1, last1) or [first2 + 1, first2 + (last1 – first1)) .

• There is enough space to hold all of the elements being copied. More formally, the requirement is that [result, result + (last1 – first1)) is a valid range.

Complexity

Linear. The operation is applied exactly last – first times in the case of the unary version, or last1 – first1 in the case of the binary version.

Example

Replace every number in an array with its negative.

const int N = 1000;

double A[N];

iota (A, A+N, 1);

transform(A, A+N, A, negate());

Calculate the sum of two vectors, storing the result in a third vector.

const int N = 1000;

vector V1(N);

vector V2(N);

vector V3(N);

iota(V1.begin(), V1.end(), 1);

fill(V2.begin(), V2.end(), 75);

assert(V2.size() >= V1.size() && V3.size() >= V1.size());

transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), plus ());

Notes

[1] The Output Iterator result is not permitted to be the same as any of the Input Iterators in the range [first, last) , with the exception of first itself. That is: transform(V.begin(), V.end(), V.begin(), fabs) is valid, but transform(V.begin(), V.end(), V.begin() + 1, fabs) is not.

See also

The function object overview, copy , generate , fill

Replace

replace

Category: algorithms

Component type: function

Prototype

template

void replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value)

Description

Replace replaces every element in the range [first, last) equal to old_value with new_value . That is: for every iterator i , if *i == old_value then it performs the assignment *i = new_value .

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.

• T is convertible to ForwardIterator 's value type.

• T is Assignable.

• T is EqualityComparable, and may be compared for equality with objects of ForwardIterator 's value type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Replace performs exactly last – first comparisons for equality, and at most last – first assignments.

Example

vector V;

V.push_back(1);

V.push_back(2);

V.push_back(3);

V.push_back(1);

replace(V.begin(), V.end(), 1, 99);

assert(V[0] == 99 && V[3] == 99);

See also

replace_if , replace_copy , replace_copy_if

replace_if

Category: algorithms

Component type: function

Prototype

template

void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value)

Description

Replace_if replaces every element in the range [first, last) for which pred returns true with new_value . That is: for every iterator i , if pred(*i) is true then it performs the assignment *i = new_value .

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.

• T is convertible to Forward Iterator 's value type.

• T is Assignable.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Replace_if performs exactly last – first applications of pred , and at most last – first assignments.

Example

Replace every negative number with 0 .

vector V;

V.push_back(1);

V.push_back(-3);

V.push_back(2);

V.push_back(-1);

replace_if(V.begin(), V.end(), bind2nd(less(), 0), –1);

assert(V[1] == 0 && V[3] == 0);

See also

replace , replace_copy , replace_copy_if

replace_copy

Category: algorithms

Component type: function

Prototype

template

OutputIterator replace_copy(InputIterator first, InputIterator last, OutputIterator result, const T& old_value, const T& new_value);

Description

Replace_copy copies elements from the range [first, last) to the range [result, result + (last-first)) , except that any element equal to old_value is not copied; new_value is copied instead. More precisely, for every integer n such that 0 <= n < last-first , replace_copy performs the assignment *(result+n) = new_value if *(first+n) == old_value , and *(result+n) = *(first+n) otherwise.

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.

• T is EqualityComparable, and may be compared for equality with objects of InputIterator 's value type.

• T is Assignable.

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

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

Интервал:

Закладка:

Сделать

Похожие книги на «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