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

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

Интервал:

Закладка:

Сделать
Requirements on types

For the first version of destroy :

• T 's destructor, ~T , is accessible.

For the second version of destroy :

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator is mutable.

• ForwardIterator 's value type has an accessible destructor.

Preconditions

For the first version of destroy :

• pointer points to a valid object of type T .

For the second version of destroy :

• [first, last) is a valid range.

• Each iterator i in [first, last) points to a valid object.

Complexity

The run-time complexity of the second version is linear: it calls the destructor exactly last – first times.

Example

class Int {

public:

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

int get() { return val; }

private:

int val;

};

int main() {

Int A[] = { Int(1), Int(2), Int(3), Int(4) };

destroy(A, A + 4);

construct(A, Int(10));

construct(A + 1, Int(11));

construct(A + 2, Int(12));

construct(A + 3, Int(13));

}

Notes

[1] In particular, destroy , along with other low-level memory allocation primitives, is used to implement container classes.

See also

Allocators, construct , uninitialized_copy , uninitialized_fill , uninitialized_fill_n , raw_storage_iterator

uninitialized_copy

Categories: allocators, algorithms

Component type: function

Prototype

template

ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);

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 each iterator in the range [result, result + (last – first)) points to uninitialized memory, then uninitialized_copy creates a copy of [first, last) in that range. That is, for each iterator i in the input range, uninitialized_copy creates a copy of *i in the location pointed to by the corresponding iterator in the output range by calling construct(&*(result + (i – first)), *i) .

Definition

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

Requirements on types

• InputIterator is a model of Input Iterator.

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator is mutable.

• ForwardIterator 's value type has a constructor that takes a single argument whose type is InputIterator 's value type.

Preconditions

• [first, last) is a valid range.

• [result, result + (last – first)) is a valid range.

• Each iterator in [result, result + (last – first)) points to a region of uninitialized memory that is large enough to store a value of ForwardIterator 's value type.

Complexity

Linear. Exactly last – first constructor calls.

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));

uninitialized_copy(A1, A1 + N, A2);

}

Notes

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

See also

Allocators, construct , destroy , uninitialized_fill , uninitialized_fill_n , raw_storage_iterator

uninitialized_copy_n

Categories: allocators, algorithms

Component type: function

Prototype

template

ForwardIterator uninitialized_copy_n(InputIterator first, Size count, ForwardIterator result);

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 each iterator in the range [result, result + n) points to uninitialized memory, then uninitialized_copy_n creates a copy of [first, first + n) in that range. That is, for each iterator i in the input range, uninitialized_copy_n creates a copy of *i in the location pointed to by the corresponding iterator in the output range by calling construct(&*(result + (i – first)), *i) .

Definition

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

• Size is an integral type.

• ForwardIterator is a model of Forward Iterator.

• ForwardIterator is mutable.

• ForwardIterator 's value type has a constructor that takes a single argument whose type is InputIterator 's value type.

Preconditions

• n >= 0

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

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

• Each iterator in [result, result + n) points to a region of uninitialized memory that is large enough to store a value of ForwardIterator 's value type.

Complexity

Linear. Exactly n constructor calls.

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);

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

Интервал:

Закладка:

Сделать

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