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

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

Интервал:

Закладка:

Сделать

[2] The declarations for rfirst and rlast are written in this clumsy form simply as an illustration of how to declare a reverse_bidirectional_iterator . List is a Reversible Container, so it provides a typedef for the appropriate instantiation of reverse_bidirectional_iterator . The usual way of declaring these variables is much simpler:

list::reverse_bidirectional_iterator rfirst = rbegin();

list::reverse_bidirectional_iterator rlast = rend();

[3] Note the implications of this remark. The variable rfirst is initialized as reverse_bidirectional_iterator<���…> rfirst(V.end()); . The value obtained when it is dereferenced, however, is *(V.end() – 1) . This is a general property: the fundamental identity of reverse iterators is &*(reverse_bidirectional_iterator(i)) == &*(i – 1) . This code sample shows why this identity is important: if [f, l) is a valid range, then it allows [reverse_bidirectional_iterator(l), reverse_bidirectional_iterator(f)) to be a valid range as well. Note that the iterator l is not part of the range, but it is required to be dereferenceable or past-the-end. There is no requirement that any such iterator precedes f .

See also

Reversible Container, reverse_iterator, Bidirectional Iterator, iterator tags, Iterator overview

raw_storage_iterator

Categories: allocators, iterators, adaptors

Component type: type

Description

In C++, the operator new allocates memory for an object and then creates an object at that location by calling a constructor. Occasionally, however, it is useful to separate those two operations. [1] If i is an iterator that points to a region of uninitialized memory, then you can use construct to create an object in the location pointed to by i . Raw_storage_iterator is an adaptor that makes this procedure more convenient. If r is a raw_storage_iterator , then it has some underlying iterator i . The expression *r = x is equivalent to construct(&*i, x) .

Example

class Int {

public:

Int(int x) : val(x) {}

int get() { return val; }

private:

int val;

};

int main() {

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

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

Int* A2 = (Int*)malloc(N * sizeof(Int));

transform(A1, A1 + N, raw_storage_iterator(A2), negate());

}

Definition

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

Template parameters
Parameter Description
OutputIterator The type of the raw_storage_iterator 's underlying iterator.
T The type that will be used as the argument to the constructor.
Model of

Output Iterator

Type requirements

• ForwardIterator is a model of Forward Iterator

• ForwardIterator 's value type has a constructor that takes a single argument of type T .

Public base classes

None.

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

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

Function Description
raw_storage_iterator(ForwardIterator i) Creates a raw_storage_iterator whose underlying iterator is i .
raw_storage_iterator& operator=(const T& val) Constructs an object of ForwardIterator 's value type at the location pointed to by the iterator, using val as the constructor's argument.
Notes

[1] In particular, this sort of low-level memory management is used in the implementation of some container classes.

[2] Note how assignment through a raw_storage_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 raw_storage_iterator itself. That is, *i 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.

See also

Allocators, construct , destroy , uninitialized_copy uninitialized_fill , uninitialized_fill_n

sequence_buffer

Categories: iterators, adaptors

Component type: type

Description

Sequence_buffer is similar to back_insert_iterator : it is an output iterator adaptor that appends elements to the end of a container.

The main difference between sequence_buffer and back_insert_iterator is that back_insert_iterator inserts elements into a sequence one element at a time; sequence_buffer , however, as the "buffer" part of the name suggests, accumulates elements into a buffer and appends the entire buffer in a single operation.

Specifically, the expression *it = v adds v to the end of it 's internal buffer. The buffer is automatically flushed when it gets full, or when it is destroyed; flushing the buffer means emptying it and appending its contents to it 's underlying container. (It is also possible to flush the buffer manually, by invoking the flush() member function.)

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

Интервал:

Закладка:

Сделать

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