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] A comparison with vector is instructive. Suppose that i is a valid vector::iterator . If an element is inserted or removed in a position that precedes i , then this operation will either result in i pointing to a different element than it did before, or else it will invalidate i entirely. (A vector::iterator will be invalidated, for example, if an insertion requires a reallocation.) However, suppose that i and j are both iterators into a vector, and there exists some integer n such that i == j + n . In that case, even if elements are inserted into the vector and i and j point to different elements, the relation between the two iterators will still hold. An slist is exactly the opposite: iterators will not be invalidated, and will not be made to point to different elements, but, for slist iterators, the predecessor/successor relationship is not invariant.

[3] 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 value_type* or of type slist::const_iterator .

[4] A similar property holds for all versions of insert() and erase() . Slist::insert() never invalidates any iterators, and slist::erase() only invalidates iterators pointing to the elements that are actually being erased.

[5] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. You can only use this member function if your compiler supports member templates.

[6] The reverse algorithm works only for bidirectional iterators. Even if reverse were extended to work with forward iterators, however, it would still be useful to have the reverse member function: it has different iterator invalidation semantics. That is, the reverse member function preserves the value that each iterator points to. Note also that the algorithm reverse(L.begin(), L.end()) uses T 's assignment operator, but the member function L.reverse() does not.

[7] The sort algorithm works only for random access iterators. In principle, however, it would be possible to write a sort algorithm that also accepted forward iterators. Even if there were such a version of sort , it would still be useful for slist to have a sort member function. That is, sort is provided as a member function not only for the sake of efficiency, but also because of the property that it preserves the values that list iterators point to.

See also

Bidirectional Iterator, Reversible Container, Sequence, list , vector

bit_vector

Category: containers

Component type: type

Description

A bit_vector is essentially a vector : it is a Sequence that has the same interface as vector . The main difference is that bit_vector is optimized for space efficiency. A vector always requires at least one byte per element, but a bit_vector only requires one bit per element.

Warning: the name bit_vector will be removed in a future release of the STL. The only reason that bit_vector is a separate class, instead of a template specialization of vector , is that this would require partial specialization of templates. On compilers that support partial specialization, bit_vector is a specialization of vector . The name bit_vector is a typedef . This typedef is not defined in the C++ standard, and is retained only for backward compatibility.

Example

bit_vector V(5);

V[0] = true;

V[1] = false;

V[2] = false;

V[3] = true;

V[4] = false;

for (bit_vector::iterator i = V.begin(); i < V.end(); ++i) cout << (*i ? '1' : '0');

cout << endl;

Definition

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

Template parameters

None. Bit_vector is not a class template.

Model of

Random access container, Back insertion sequence.

Type requirements

None.

Public base classes

None.

Members
Member Where defined Description
value_type Container The type of object stored in the bit_vector: bool
reference bit_vector A proxy class that acts as a reference to a single bit. See below for details.
const_reference Container Const reference to value_type . In bit_vector this is simply defined to be bool .
size_type Container An unsigned integral type.
difference_type Container A signed integral type.
iterator Container Iterator used to iterate through a bit_vector .
const_iterator Container Const iterator used to iterate through a bit_vector .
reverse_iterator Reversible Container Iterator used to iterate backwards through a bit_vector .
const_reverse_iterator Reversible Container Const iterator used to iterate backwards through a bit_vector .
iterator begin() Container Returns an iterator pointing to the beginning of the bit_vector .
iterator end() Container Returns an iterator pointing to the end of the bit_vector .
const_iterator begin() const Container Returns a const_iterator pointing to the beginning of the bit_vector .
const_iterator end() const Container Returns a const_iterator pointing to the end of the bit_vector .
reverse_iterator rbegin() Reversible Container Returns a reverse_iterator pointing to the beginning of the reversed bit_vector.
reverse_iterator rend() Reversible Container Returns a reverse_iterator pointing to the end of the reversed bit_vector.
const_reverse_iterator rbegin() const Reversible Container Returns a const_reverse_iterator pointing to the beginning of the reversed bit_vector.
const_reverse_iterator rend() const Reversible Container Returns a const_reverse_iterator pointing to the end of the reversed bit_vector.
size_type size() const Container Returns the number of elements in the bit_vector .
size_type max_size() const Container Returns the largest possible size of the bit_vector .
size_type capacity() const bit_vector See below.
bool empty() const Container true if the bit_vector '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.
bit_vector() Container Creates an empty bit_vector.
bit_vector(size_type n) Sequence Creates a bit_vector with n elements.
bit_vector(size_type n, bool t) Sequence Creates a bit_vector with n copies of t .
bit_vector(const bit_vector&) Container The copy constructor.
template bit_vector(InputIterator, InputIterator)[1] Sequence Creates a bit_vector with a copy of a range.
~bit_vector() Container The destructor.
bit_vector& operator=(const bit_vector&) Container The assignment operator
void reserve(size_t) bit_vector See below.
reference front() Sequence Returns the first element.
const_reference front() const 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_back(const T&) Back Insertion Sequence Inserts a new element at the end.
void pop_back() Back Insertion Sequence Removes the last element.
void swap(bit_vector&) Container Swaps the contents of two bit_vectors.
void swap(bit_vector::reference x, bit_vector::reference y) bit_vector See below.
iterator insert(iterator pos, bool x) Sequence Inserts x before pos .
template void insert(iterator pos, InputIterator f, InputIterator l)[1] Sequence Inserts the range [f, l) before pos .
void insert(iterator pos, size_type n, bool x) Sequence Inserts n copies of x before pos .
void erase(iterator pos) Sequence Erases the element at position pos .
void erase(iterator first, iterator last) Sequence Erases the range [first, last)
void clear() Sequence Erases all of the elements.
bool operator==(const bit_vector&, const bit_vector&) Forward Container Tests two bit_vectors for equality. This is a global function, not a member function.
bool operator<(const bit_vector&, const bit_vector&) Forward Container Lexicographical comparison. This is a global function, not a member function.
New members

These members are not defined in the Random access container and Back insertion sequence requirements, but are specific to vector .

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

Интервал:

Закладка:

Сделать

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