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

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

Интервал:

Закладка:

Сделать
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

• UnaryFunction is a model of Unary Function

• UnaryFunction does not apply any non-constant operation through its argument.

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

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Exactly last – first applications of UnaryFunction .

Example

template struct print : public unary_function {

print(ostream& out) : os(out), count(0) {}

void operator() (T x) { os << x << ' '; ++count; }

ostream& os;

int count;

};

int main() {

int A[] = {1, 4, 2, 8, 5, 7};

const int N = sizeof(A) / sizeof(int);

print P = for_each(A, A + N, print(cout));

cout << endl << P.count << " objects printed." << endl;

}

Notes

[1] This return value is sometimes useful, since a function object may have local state. It might, for example, count the number of times that it is called, or it might have a status flag to indicate whether or not a call succeeded.

See also

The function object overview, count , copy

find

Category: algorithms

Component type: function

Prototype

template

InputIterator find(InputIterator first, InputIterator last, const EqualityComparable& value);

Description

Returns the first iterator i in the range [first, last) such that *i == value . Returns last if no such iterator exists.

Definition

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

Requirements on types

• EqualityComparable is a model of EqualityComparable.

• InputIterator is a model of InputIterator.

• Equality is defined between objects of type EqualityComparable and objects of InputIterator's value type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear: at most last – first comparisons for equality.

Example

list L;

L.push_back(3);

L.push_back(1);

L.push_back(7);

list::iterator result = find(L.begin(), L.end(), 7);

assert(result == L.end() || *result == 7);

See also

find_if.

find_if

Category: algorithms

Component type: function

Prototype

template

InputIterator find_if(InputIterator first, InputIterator last, Predicate pred);

Description

Returns the first iterator i in the range [first, last) such that pred(*i) is true. Returns last if no such iterator exists.

Definition

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

Requirements on types

• Predicate is a model of Predicate.

• InputIterator is a model of InputIterator.

• The value type of InputIterator is convertible to the argument type of Predicate.

Preconditions

• [first, last) is a valid range.

• For each iterator i in the range [first, last) , *i is in the domain of Predicate.

Complexity

Linear: at most last – first applications of Pred .

Example

list L;

L.push_back(-3);

L.push_back(0);

L.push_back(3); L.push_back(-2);

list::iterator result = find_if(L.begin(), L.end(), bind2nd(greater(), 0));

assert(result == L.end() || *result > 0);

See also

find.

adjacent_find

Category: algorithms

Component type: function

Prototype

Adjacent_find is an overloaded name; there are actually two adjacent_find functions.

template

ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last);

template

ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate binary_pred);

Description

The first version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last) , and such that *i == *(i+1) . It returns last if no such iterator exists.

The second version of adjacent_find returns the first iterator i such that i and i+1 are both valid iterators in [first, last) , and such that binary_pred(*i, *(i+1)) is true . It returns last if no such iterator exists.

Definition

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

Requirements on types

For the first version:

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator 's value type is Equality Comparable.

For the second version:

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator 's value type is convertible to BinaryPredicate 's first argument type and to its second argument type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. If first == last then no comparison are performed; otherwise, at most (last – first) – 1 comparisons.

Example

Find the first element that is greater than its successor.

int A[] = {1, 2, 3, 4, 6, 5, 7, 8};

const int N = sizeof(A) / sizeof(int);

const int* p = adjacent_find(A, A + N, greater ());

cout << "Element " << p – A << " is out of order: " << *p << " > " << *(p + 1) << "." << endl;

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

Интервал:

Закладка:

Сделать

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