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

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

Интервал:

Закладка:

Сделать

This difference has two implications. First, sequence_buffer is only useful if appending an array of N elements is much more efficient than inserting a single element N times. Second, sequence_buffer assumes that it can insert elements at the end of a container using an append member function. This member function is not part of the Container or Sequence requirements. The sequence_buffer adaptor can be used with rope , but not with any of the other containers in the library. (This is the reason why sequence_buffer is defined in the file rope.h, instead of in iterator.h.)

If you want to build up a string one character at a time, it is much more efficient to use sequence_buffer than to repeatedly add single characters to the end of a rope .

Example

int main() {

const char* const s = "this is a test";

const int N = strlen(s);

crope r;

transform(s, s + N, sequence_buffer(r), toupper);

cout << "r = " << r << endl;

}

Definition

Defined in the header rope, and in the backward-compatibility header rope.h. The sequence_buffer class, and the rope header, are SGI extensions; they are not part of the C++ standard.

Template parameters
Parameter Description Default
Container The type of the underlying container that elements are being written to. [1]
buf_sz Number of elements in the buffer. This is a number, not a type. buf_sz has type size_t . 100
Model of

Output Iterator.

Type requirements

• Container is a variable-sized Forward Container

• Container 's value type T is a model of Default Constructible, as well as Assignable.

• Container has a member function that appends a range. Specifically: If x is an object of type Container and f and l are of type T* , then x.append(f, l) appends the range [f, l) to x . [1]

Public base classes

output_iterator

Members
Member Where defined Description
value_type sequence_buffer The underlying container's value type.
sequence_buffer(Container& C) sequence_buffer Create a sequence_buffer whose underlying container is C .
sequence_buffer() Default Constructible The default constructor. The resulting iterator is singular.
sequence_buffer(const sequence_buffer&) Assignable Copy constructor.
sequence_buffer& operator=(const sequence_buffer& s) Assignable Assignment operator.
sequence_buffer& operator=(sequence_buffer& s) Assignable Faster version of assignment operator.
sequence_buffer& operator=(const value_type&) Output Iterator Used to implement the Output Iterator requirement *i = t . [2]
sequence_buffer& operator*() Output Iterator Used to implement the Output Iterator requirement *i = t . [2]
sequence_buffer& operator++() Output Iterator Preincrement
sequence_buffer& operator++(int) Output Iterator Postincrement
void flush() sequence_buffer Flush the buffer.
void push_back(value_type) sequence_buffer i.push_back(x) is equivalent to *i = x .
void append(value_type* s, size_t len) sequence_buffer Append multiple values.
New members

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

Function Description
value_type The underlying container's value type. That is, typename Container::value_type .
sequence_buffer(Container& C) Create a sequence_buffer whose underlying container is C . Elements appended to the sequence_buffer will be appended to C whenever the sequence_buffer is flushed.
void flush() Append all elements in the buffer to the underlying container, and empty the buffer. That is, make the underlying container consistent with the sequence_buffer . Note that flush is called automatically whenever the buffer is full, and also by sequence_buffer 's destructor. Sometimes, however, it is useful to be sure that the buffer is flushed at a particular time.
void push_back(value_type x) Append x to the sequence_buffer . Note that this member function is strictly unnecessary: i.push_back(x) is just alternate syntax for *i = x .
void append(value_type* s, size_t len) Append the range [s, s + len) to the sequence_buffer . Note that i.append(s, n) is just the same as copy(s, s + n, i) . The append member function, however, is faster.
Notes

[1] Despite the name "sequence_buffer", this adaptor cannot actually be used with arbitrary sequences: it requires that the template argument Container have an append member function that can insert multiple elements at the end of the container. This member function is not part of the Sequence requirements. This means that sequence_buffer can be used with rope , but not with any of the other predefined container classes.

[2] Note how assignment through a sequence_buffer 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 output operation. In this case, for the sake of simplicity, the proxy object is the sequence_buffer 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.

See also

Output Iterator, rope , front_insert_iterator , back_insert_iterator , insert_iterator

Algorithms

Non-mutating algorithms

for_each

Category: algorithms

Component type: function

Prototype

template

UnaryFunction for_each(InputIterator first, InputIterator last, UnaryFunction f);

Description

For_each applies the function object f to each element in the range [first, last) ; f 's return value, if any, is ignored. Applications are performed in forward order, i.e. from first to last . For_each returns the function object after it has been applied to each element. [1]

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

Интервал:

Закладка:

Сделать

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