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

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

Интервал:

Закладка:

Сделать
Example

Insert a range of elements into a list .

list L;

L.push_front(3);

insert_iterator > ii(L, L.begin());

*ii++ = 0;

*ii++ = 1;

*ii++ = 2;

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

// The values that are printed are 0 1 2 3.

Merge two sorted lists, inserting the resulting range into a set . Note that a set never contains duplicate elements.

int main() {

const int N = 6;

int A1[N] = {1, 3, 5, 7, 9, 11};

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

set result;

merge (A1, A1 + N, A2, A2 + N,

inserter(result, result.begin()));

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

cout << endl;

// The output is "1 2 3 4 5 6 7 9 11".

}

Definition

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

Template parameters
Parameter Description
Container The type of Container into which values will be inserted.
Model of

Output Iterator. An insert iterator's set of value types (as defined in the Output Iterator requirements) consists of a single type: Container::value_type .

Type requirements

• The template parameter Container is a model of Container.

• Container is variable-sized, as described in the Container requirements.

• Container has a two-argument insert member function. Specifically, if c is an object of type Container , p is an object of type Container::iterator and v is an object of type Container::value_type , then c.insert(p, v) must be a valid expression.

Public base classes

None.

Members
Member Where defined Description
insert_iterator(Container&, Container::iterator) insert_iterator See below.
insert_iterator(const insert_iterator&) Trivial Iterator The copy constructor
insert_iterator& operator=(const insert_iterator&) Trivial Iterator The assignment operator
insert_iterator& operator*() Output Iterator Used to implement the output iterator expression *i = x . [2]
insert_iterator& operator=(const Container::value_type&) Output Iterator Used to implement the output iterator expression *i = x . [2]
insert_iterator& operator++() Output Iterator Preincrement.
insert_iterator& operator++(int) Output Iterator Postincrement.
output_iterator_tag iterator_category(const insert_iterator&) iterator tags Returns the iterator's category. This is a global function, not a member.
template inserter(Container& C, Iter i); insert_iterator See below.
New members

These members are not defined in the Output Iterator requirements, but are specific to insert_iterator .

Member Description
insert_iterator(Container& C, Container::iterator i) Constructs an insert_iterator that inserts objects in C . If Container is a Sequence, then each object will be inserted immediately before the element pointed to by i . If C is a Sorted Associative Container, then the first insertion will use i as a hint for beginning the search. The iterator i must be a dereferenceable or past-the-end iterator in C .
template inserter(Container& C, Iter i); Equivalent to insert_iterator(C, i) . [2] This is a global function, not a member function.
Notes

[1] Note the difference between assignment through a Container::iterator and assignment through an insert_iterator . If i is a valid Sequence::iterator , then it points to some particular element in the container; the expression *i = t replaces that element with t , and does not change the total number of elements in the container. If ii is a valid insert_iterator , however, then the expression *ii = t is equivalent, for some container c and some valid container::iterator j , to the expression c.insert(j, t) . That is, it does not overwrite any of c 's elements and it does change c 's size.

[2] Note how assignment through an insert_iterator is implemented. In general, unary operator* must be defined so that it returns a proxy object, where the proxy object defines operator= to perform the insert operation. In this case, for the sake of simplicity, the proxy object is the insert_iterator itself. That is, *i simply returns i , and *i = t is equivalent to i = t . You should not, however, rely on this behavior. It is an implementation detail, and it is not guaranteed to remain the same in future versions.

[3] This function exists solely for the sake of convenience: since it is a non-member function, the template parameters may be inferred and the type of the insert_iterator need not be declared explicitly. One easy way to reverse a range and insert it into a Sequence S , for example, is reverse_copy(first, last, inserter(S, S.begin())) .

See also

front_insert_iterator, back_insert_iterator, Output Iterator, Sequence, Iterator overview

reverse_iterator

Categories: iterators, adaptors

Component type: type

Description

Reverse_iterator is an iterator adaptor that enables backwards traversal of a range. Operator++ applied to an object of class reverse_iterator means the same thing as operator-- applied to an object of class RandomAccessIterator . There are two different reverse iterator adaptors: the class reverse_iterator has a template argument that is a Random Access Iterator, and the class reverse_bidirectional_iterator has a template argument that is a Bidirectional Iterator. [1]

Example

template

void forw(const vector& V) {

vector::iterator first = V.begin();

vector::iterator last = V.end();

while (first != last) cout << *first++ << endl;

}

template

void rev(const vector& V) {

typedef reverse_iterator::iterator, T, vector::reference_type, vector::difference_type> reverse_iterator; [2]

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

Интервал:

Закладка:

Сделать

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