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

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

Интервал:

Закладка:

Сделать
Member Description
reference A proxy class that acts as a reference to a single bit; the reason it exists is to allow expressions like V[0] = true . (A proxy class like this is necessary, because the C++ memory model does not include independent addressing of objects smaller than one byte.) The public member functions of reference are operator bool() const , reference& operator=(bool) , and void flip() . That is, reference acts like an ordinary reference: you can convert a reference to bool , assign a bool value through a reference , or flip the bit that a reference refers to.
size_type capacity() const Number of bits for which memory has been allocated. capacity() is always greater than or equal to size() . [2] [3]
void reserve(size_type n) If n is less than or equal to capacity() , this call has no effect. Otherwise, it is a request for the allocation of additional memory. If the request is successful, then capacity() is greater than or equal to n ; otherwise, capacity() is unchanged. In either case, size() is unchanged. [2] [4]
void swap(bit_vector::reference x, bit_vector::reference y) Swaps the bits referred to by x and y . This is a global function, not a member function. It is necessary because the ordinary version of swap takes arguments of type T& , and bit_vector::reference is a class, not a built-in C++ reference.
Notes

[1] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. If your compiler supports member templates, you can call this function with any type of input iterator. If your compiler does not yet support member templates, though, then the arguments must either be of type const bool* or of type bit_vector::const_iterator .

[2] Memory will be reallocated automatically if more than capacity() – size() bits are inserted into the bit_vector. Reallocation does not change size() , nor does it change the values of any bits of the bit_vector. It does, however, increase capacity() , and it invalidates [5] any iterators that point into the bit_vector.

[3] When it is necessary to increase capacity() , bit_vector usually increases it by a factor of two. It is crucial that the amount of growth is proportional to the current capacity() , rather than a fixed constant: in the former case inserting a series of bits into a bit_vector is a linear time operation, and in the latter case it is quadratic.

[4] reserve() is used to cause a reallocation manually. The main reason for using reserve() is efficiency: if you know the capacity to which your bit_vector must eventually grow, then it is probably more efficient to allocate that memory all at once rather than relying on the automatic reallocation scheme. The other reason for using reserve() is to control the invalidation of iterators. [5]

[5] A bit_vector 's iterators are invalidated when its memory is reallocated. Additionally, inserting or deleting a bit in the middle of a bit_vector invalidates all iterators that point to bits following the insertion or deletion point. It follows that you can prevent a bit_vector's iterators from being invalidated if you use reserve() to preallocate as much storage as the bit_vector will ever use, and if all insertions and deletions are at the bit_vector's end.

See also

vector

Associative Containers

set

Category: containers

Component type: type

Description

Set is a Sorted Associative Container that stores objects of type Key . Set is a Simple Associative Container, meaning that its value type, as well as its key type, is Key . It is also a Unique Associative Container, meaning that no two elements are the same.

Set and multiset are particularly well suited to the set algorithms includes , set_union , set_intersection , set_difference , and set_symmetric_difference . The reason for this is twofold. First, the set algorithms require their arguments to be sorted ranges, and, since set and multiset are Sorted Associative Containers, their elements are always sorted in ascending order. Second, the output range of these algorithms is always sorted, and inserting a sorted range into a set or multiset is a fast operation: the Unique Sorted Associative Container and Multiple Sorted Associative Container requirements guarantee that inserting a range takes only linear time if the range is already sorted.

Set has the important property that inserting a new element into a set does not invalidate iterators that point to existing elements. Erasing an element from a set also does not invalidate any iterators, except, of course, for iterators that actually point to the element that is being erased.

Example

struct ltstr {

bool operator()(const char* s1, const char* s2) const {

return strcmp(s1, s2) < 0;

}

};

int main() {

const int N = 6;

const char* a[N] = {"isomer", "ephemeral", "prosaic", "nugatory", "artichoke", "serif"};

const char* b[N] = {"flat", "this", "artichoke", "frigate", "prosaic", "isomer"};

set A(a, a + N);

set B(b, b + N);

set C;

cout << "Set A: ";

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

cout << endl;

cout << "Set B: ";

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

cout << endl;

cout << "Union: ";

set_union(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " "), ltstr());

cout << endl;

cout << "Intersection: ";

set_intersection(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " "), ltstr());

cout << endl;

set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin()), ltstr());

cout << "Set C (difference of A and B): ";

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

cout << endl;

}

Definition

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

Template parameters
Parameter Description Default
Key The set's key type and value type. This is also defined as set::key_type and set::value_type
Compare The key comparison function, a Strict Weak Ordering whose argument type is key_type ; it returns true if its first argument is less than its second argument, and false otherwise. This is also defined as set::key_compare and set::value_compare . less
Alloc The set 's allocator, used for all internal memory management. alloc
Model of

Unique Sorted Associative Container, Simple Associative Container

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

Интервал:

Закладка:

Сделать

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