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

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

Интервал:

Закладка:

Сделать

• StrictWeakOrdering is a model of Strict Weak Ordering.

• BidirectionalIterator 's value type is convertible to StrictWeakOrdering 's argument type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. At most (last – first) / 2 swaps.

Example

int main() {

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

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

cout << "Initially: ";

copy (A, A+N, ostream_iterator(cout, " "));

cout << endl;

prev_permutation(A, A+N);

cout << "After prev_permutation: ";

copy (A, A+N, ostream_iterator(cout, " "));

cout << endl;

next_permutation(A, A+N);

cout << "After next_permutation: ";

copy (A, A+N, ostream_iterator(cout, " "));

cout << endl;

}

Notes

[1] If all of the elements in [first, last) are distinct from each other, then there are exactly N! permutations. If some elements are the same as each other, though, then there are fewer. There are, for example, only three ( 3!/2! ) permutations of the elements 1 1 2 .

[2] Note that the lexicographically greatest permutation is, by definition, sorted in nonascending order.

See also

next_permutation , lexicographical_compare , LessThan Comparable, Strict Weak Ordering, sort

Generalized numeric algorithms

iota

Category: algorithms

Component type: function

Prototype

template

void iota(ForwardIterator first, ForwardIterator last, T value);

Description

Iota assigns sequentially increasing values to a range. That is, it assigns value to *first , value + 1 to *(first + 1) and so on. In general, each iterator i in the range [first, last) is assigned value + (i – first) . [1]

Definition

Defined in the standard header numeric, and in the nonstandard backward-compatibility header algo.h. This function is an SGI extension; it is not part of the C++ standard.

Requirements on types

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator is mutable.

• T is Assignable.

• If x is an object of type T , then x++ is defined.

• T is convertible to ForwardIterator 's value type.

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Exactly last – first assignments.

Example

int main() {

vector V(10);

iota(V.begin(), V.end(), 7);

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

cout << endl;

}

Notes

[1] The name iota is taken from the programming language APL.

See also

fill , generate , partial_sum

accumulate

Category: algorithms

Component type: function

Prototype

Accumulate is an overloaded name; there are actually two accumulate functions.

template

T accumulate(InputIterator first, InputIterator last, T init);

template

T accumulate(InputIterator first, InputIterator last, T init, BinaryFunction binary_op);

Description

Accumulate is a generalization of summation: it computes the sum (or some other binary operation) of init and all of the elements in the range [first, last) . [1]

The function object binary_op is not required to be either commutative or associative: the order of all of accumulate 's operations is specified. The result is first initialized to init . Then, for each iterator i in [first, last) , in order from beginning to end, it is updated by result = result + *i (in the first version) or result = binary_op(result, *i) (in the second version).

Definition

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

Requirements on types

For the first version, the one that takes two arguments:

• InputIterator is a model of Input Iterator.

• T is a model of Assignable.

• If x is an object of type T and y is an object of InputIterator 's value type, then x + y is defined.

• The return type of x + y is convertible to T .

For the second version, the one that takes three arguments:

• InputIterator is a model of Input Iterator.

• T is a model of Assignable.

• BinaryFunction is a model of Binary Function.

• T is convertible to BinaryFunction 's first argument type.

• The value type of InputIterator is convertible to BinaryFunction 's second argument type.

• BinaryFunction 's return type is convertible to T .

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Exactly last – first invocations of the binary operation.

Example

int main() {

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

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

cout << "The sum of all elements in A is " << accumulate(A, A + N, 0) << endl;

cout << "The product of all elements in A is " << accumulate(A, A + N, 1, multiplies()) << endl;

}

Notes

[1] There are several reasons why it is important that accumulate starts with the value init . One of the most basic is that this allows accumulate to have a well-defined result even if [first, last) is an empty range: if it is empty, the return value is init . If you want to find the sum of all of the elements in [first, last) , you can just pass 0 as init .

See also

inner_product , partial_sum , adjacent_difference , count

inner_product

Category: algorithms

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

Интервал:

Закладка:

Сделать

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

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


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

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