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
size_type capacity() const Number of elements 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 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]
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 be of type const value_type* .

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

[3] When it is necessary to increase capacity() , 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 elements into a vector is a linear time operation, and in the latter case it is quadratic.

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

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

See also

deque, list, slist

deque

Category: containers

Component type: type

Description

A deque [1] is very much like a vector : like vector , it is a sequence that supports random access to elements, constant time insertion and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle.

The main way in which deque differs from vector is that deque also supports constant time insertion and removal of elements at the beginning of the sequence [2]. Additionally, deque does not have any member functions analogous to vector 's capacity() and reserve() , and does not provide any of the guarantees on iterator validity that are associated with those member functions. [3]

Example

deque Q;

Q.push_back(3);

Q.push_front(1);

Q.insert(Q.begin() + 1, 2);

Q[2] = 0;

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

// The values that are printed are 1 2 0

Definition

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

Template parameters
Parameter Description Default
T The deque's value type: the type of object that is stored in the deque.
Alloc The deque 's allocator, used for all internal memory management. alloc
Model of

Random access container, Front insertion sequence, Back insertion sequence.

Type requirements

None, except for those imposed by the requirements of Random access container, Front insertion sequence, and Back insertion sequence.

Public base classes

None.

Members
Member Where defined Description
value_type Container The type of object, T , stored in the deque.
pointer Container Pointer to T .
reference Container Reference to T
const_reference Container Const reference to T
size_type Container An unsigned integral type.
difference_type Container A signed integral type.
iterator Container Iterator used to iterate through a deque .
const_iterator Container Const iterator used to iterate through a deque .
reverse_iterator Reversible Container Iterator used to iterate backwards through a deque .
const_reverse_iterator Reversible Container Const iterator used to iterate backwards through a deque .
iterator begin() Container Returns an iterator pointing to the beginning of the deque .
iterator end() Container Returns an iterator pointing to the end of the deque .
const_iterator begin() const Container Returns a const_iterator pointing to the beginning of the deque .
const_iterator end() const Container Returns a const_iterator pointing to the end of the deque .
reverse_iterator rbegin() Reversible Container Returns a reverse_iterator pointing to the beginning of the reversed deque.
reverse_iterator rend() Reversible Container Returns a reverse_iterator pointing to the end of the reversed deque.
const_reverse_iterator rbegin() const Reversible Container Returns a const_reverse_iterator pointing to the beginning of the reversed deque.
const_reverse_iterator rend() const Reversible Container Returns a const_reverse_iterator pointing to the end of the reversed deque.
size_type size() const Container Returns the size of the deque .
size_type max_size() const Container Returns the largest possible size of the deque .
bool empty() const Container true if the deque 's size is 0 .
reference operator[](size_type n) Random Access Container Returns the n 'th element.
const_reference operator[](size_type n) const Random Access Container Returns the n 'th element.
deque() Container Creates an empty deque.
deque(size_type n) Sequence Creates a deque with n elements.
deque(size_type n, const T& t) Sequence Creates a deque with n copies of t .
deque(const deque&) Container The copy constructor
template deque(InputIterator f, InputIterator l)[4] Sequence Creates a deque with a copy of a range.
~deque() Container The destructor.
deque& operator=(const deque&) Container The assignment operator
reference front() Front Insertion Sequence Returns the first element.
const_reference front() const Front Insertion Sequence Returns the first element.
reference back() Back Insertion Sequence Returns the last element.
const_reference back() const Back Insertion Sequence Returns the last element.
void push_front(const T&) Front Insertion Sequence Inserts a new element at the beginning.
void push_back(const T&) Back Insertion Sequence Inserts a new element at the end.
void pop_front() Front Insertion Sequence Removes the first element.
void pop_back() Back Insertion Sequence Removes the last element.
void swap(deque&) Container Swaps the contents of two deques.
iterator insert(iterator pos, const T& x) Sequence Inserts x before pos .
template void insert(iterator pos, InputIterator f, InputIterator l)[4] Sequence Inserts the range [f, l) before pos .
void insert(iterator pos, size_type n, const T& x) Sequence Inserts n copies of x before pos .
iterator erase(iterator pos) Sequence Erases the element at position pos .
iterator erase(iterator first, iterator last) Sequence Erases the range [first, last)
void clear() Sequence Erases all of the elements.
void resize(n, t = T()) Sequence Inserts or erases elements at the end such that the size becomes n .
bool operator==(const deque&, const deque&) Forward Container Tests two deques for equality. This is a global function, not a member function.
bool operator<(const deque&, const deque&) Forward Container Lexicographical comparison. This is a global function, not a member function.
New members

All of deque 's members are defined in the Random access container, Front insertion sequence, and Back insertion sequence requirements. Deque does not introduce any new members.

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

Интервал:

Закладка:

Сделать

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