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

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

Интервал:

Закладка:

Сделать

Categories: iterators, adaptors

Component type: type

Description

Back_insert_iterator is an iterator adaptor that functions as an Output Iterator: assignment through a back_insert_iterator inserts an object after the last element of a Back Insertion Sequence. [1]

Example

list L;

L.push_front(3);

back_insert_iterator > ii(L);

*ii++ = 0;

*ii++ = 1;

*ii++ = 2;

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

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

Definition

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

Template parameters
Parameter Description
BackInsertionSequence The type of Back Insertion Sequence 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: BackInsertionSequence::value_type .

Type requirements

The template parameter BackInsertionSequence must be a Back Insertion Sequence.

Public base classes

None.

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

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

Member function Description
back_insert_iterator(BackInsertionSequence& S) Constructs a back_insert_iterator that inserts objects after the last element of S . (That is, it inserts objects just before S 's past-the-end iterator.)
template back_insert_iterator back_inserter(BackInsertionSequence& S); Equivalent to back_insert_iterator(S) . [3] This is a global function, not a member function.
Notes

[1] Note the difference between assignment through a BackInsertionSequence::iterator and assignment through a back_insert_iterator . If i is a valid BackInsertionSequence::iterator , then it points to some particular element in the back insertion sequence; the expression *i = t replaces that element with t , and does not change the total number of elements in the back insertion sequence. If ii is a valid back_insert_iterator , however, then the expression *ii = t is equivalent, to the expression seq.push_back(t) . That is, it does not overwrite any of seq 's elements and it does change seq 's size.

[2] Note how assignment through a back_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 back_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 back_insert_iterator need not be declared explicitly. One easy way to reverse a range and insert it at the end of a Back Insertion Sequence S , for example, is reverse_copy(first, last, back_inserter(S)) .

See also

insert_iterator, front_insert_iterator, Output Iterator, Back Insertion Sequence, Sequence, Iterator overview

insert_iterator

Categories: iterators, adaptors

Component type: type

Description

Insert_iterator is an iterator adaptor that functions as an Output Iterator: assignment through an insert_iterator inserts an object into a Container. Specifically, if ii is an insert_iterator , then ii keeps track of a Container c and an insertion point p ; the expression *ii = x performs the insertion c.insert(p, x) . [1]

There are two different Container concepts that define this expression: Sequence, and Sorted Associative Container. Both concepts define insertion into a container by means of c.insert(p, x) , but the semantics of this expression is very different in the two cases.

For a Sequence S , the expression S.insert(p, x) means to insert the value ximmediately before the iterator p . That is, the two-argument version of insert allows you to control the location at which the new element will be inserted. For a Sorted Associative Container, however, no such control is possible: the elements in a Sorted Associative Container always appear in ascending order of keys. Sorted Associative Containers define the two-argument version of insert as an optimization. The first argument is only a hint: it points to the location where the search will begin.

If you assign through an insert_iterator several times, then you will be inserting several elements into the underlying container. In the case of a Sequence, they will appear at a particular location in the underlying sequence, in the order in which they were inserted: one of the arguments to insert_iterator 's constructor is an iterator p , and the new range will be inserted immediately before p .

In the case of a Sorted Associative Container, however, the iterator in the insert_iterator 's constructor is almost irrelevant. The new elements will not necessarily form a contiguous range; they will appear in the appropriate location in the container, in ascending order by key. The order in which they are inserted only affects efficiency: inserting an already-sorted range into a Sorted Associative Container is an O(N ) operation.

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

Интервал:

Закладка:

Сделать

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