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

copy_backward , copy_n

copy_n

Category: algorithms

Component type: function

Prototype

template

OutputIterator copy_n(InputIterator first, Size count, OutputIterator result);

Description

Copy_n copies elements from the range [first, first + n) to the range [result, result + n) . That is, it performs the assignments *result = *first , *(result + 1) = *(first + 1) , and so on. Generally, for every integer i from 0 up to (but not including) n , copy_n performs the assignment *(result + i) = *(first + i) . Assignments are performed in forward order, i.e. in order of increasing n . [1]

The return value is result + n .

Definition

Defined in the standard header algorithm, 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

• InputIterator is a model of Input Iterator.

• OutputIterator is a model of Output Iterator.

• Size is an integral type.

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

Preconditions

• n >= 0 .

• [first, first + n) is a valid range.

• result is not an iterator within the range [first, first + n) .

• [result, result + n) is a valid range.

Complexity

Linear. Exactly n assignments are performed.

Example

vector V(5);

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

list L(V.size());

copy_n(V.begin(), V.size(), L.begin());

assert(equal(V.begin(), V.end(), L.begin()));

Notes

[1] Copy_n is almost, but not quite, redundant. If first is an input iterator, as opposed to a forward iterator, then the copy_n operation can't be expressed in terms of copy .

See also

copy , copy_backward

copy_backward

Category: algorithms

Component type: function

Prototype

template

BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result);

Description

Copy_backward copies elements from the range [first, last) to the range [result – (last – first), result) [1]. That is, it performs the assignments *(result – 1) = *(last – 1) , *(result – 2) = *(last – 2) , and so on. Generally, for every integer n from 0 to last – first , copy_backward performs the assignment *(result – n – 1) = *(last – n – 1) . Assignments are performed from the end of the input sequence to the beginning, i.e. in order of increasing n . [2]

The return value is result – (last – first)

Definition

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

Requirements on types

• BidirectionalIterator1 and BidirectionalIterator2 are models of BidirectionalIterator.

• BidirectionalIterator1's value type is convertible to BidirectionalIterator2's value type.

Preconditions

• [first, last) is a valid range.

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

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

Complexity

Linear. Exactly last – first assignments are performed.

Example

vector V(15);

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

copy_backward(V.begin(), V.begin() + 10, V.begin() + 15);

Notes

[1] Result is an iterator that points to the end of the output range. This is highly unusual: in all other STL algorithms that denote an output range by a single iterator, that iterator points to the beginning of the range.

[2] The order of assignments matters in the case where the input and output ranges overlap: copy_backward may not be used if result is in the range [first, last) . That is, it may not be used if the end of the output range overlaps with the input range, but it may be used if the beginning of the output range overlaps with the input range; copy has opposite restrictions. If the two ranges are completely nonoverlapping, of course, then either algorithm may be used.

See also

copy , copy_n

Swap

swap

Category: algorithms

Component type: function

Prototype

template

void swap(Assignable& a, Assignable& b);

Description

Assigns the contents of a to b and the contents of b to a . This is used as a primitive operation by many other algorithms.

Definition

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

Requirements on types

• Assignable is a model of Assignable.

Preconditions

None.

Complexity

Amortized constant time. [1] [2]

Example

int x = 1;

int y = 2;

assert(x == 1 && y == 2);

swap(x, y);

assert(x == 2 && y == 1);

Notes

[1] The time required to swap two objects of type T will obviously depend on the type; "constant time" does not mean that performance will be the same for an 8-bit char as for a 128-bit complex .

[2] This implementation of swap makes one call to a copy constructor and two calls to an assignment operator; roughly, then, it should be expected to take about the same amount of time as three assignments. In many cases, however, it is possible to write a specialized version of swap that is far more efficient. Consider, for example, swapping two vector s each of which has N elements. The unspecialized version requires 3*N assignments of double , but a specialized version requires only nine pointer assignments. This is importantbecause swap is used as a primitive operation in many other STL algorithms, and because containers of containers ( list > , for example) are very common. The STL includes specialized versions of swap for all container classes. User-defined types should also provide specialized versions of swap whenever it is possible to write one that is more efficient than the general version.

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

Интервал:

Закладка:

Сделать

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