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 function Description
data_type& operator[](const key_type& k)[3] Returns a reference to the object that is associated with a particular key. If the map does not already contain such an object, operator[] inserts the default object data_type() . [3]
Notes

[1] Map::iterator is not a mutable iterator, because map::value_type is not Assignable. That is, if i is of type map::iterator and p is of type map::value_type , then *i = p is not a valid expression. However, map::iterator isn't a constant iterator either, because it can be used to modify the object that it points to. Using the same notation as above, (*i).second = p is a valid expression. The same point applies to map::reverse_iterator .

[2] 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 map::const_iterator .

[3] Since operator[] might insert a new element into the map , it can't possibly be a const member function. Note that the definition of operator[] is extremely simple: m[k] is equivalent to (*((m.insert(value_type(k, data_type()))).first)).second . Strictly speaking, this member function is unnecessary: it exists only for convenience.

See also

Associative Container, Sorted Associative Container, Pair Associative Container, Unique Sorted Associative Container, set multiset , multimap , hash_set , hash_map , hash_multiset , hash_multimap

multiset

Category: containers

Component type: type

Description

Multiset is a Sorted Associative Container that stores objects of type Key . Multiset is a Simple Associative Container, meaning that its value type, as well as its key type, is Key . It is also a Multiple Associative Container, meaning that two or more elements may be identical.

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.

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

Example

int main() {

const int N = 10;

int a[N] = {4, 1, 1, 1, 1, 1, 0, 5, 1, 0};

int b[N] = {4, 4, 2, 4, 2, 4, 0, 1, 5, 5};

multiset A(a, a + N);

multiset B(b, b + N);

multiset 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, " "));

cout << endl;

cout << "Intersection: ";

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

cout << endl;

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

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 multiset.h.

Template parameters
Parameter Description Default
Key The set's key type and value type. This is also defined as multiset::key_type and multiset::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 multiset::key_compare and multiset::value_compare . less
Alloc The multiset 's allocator, used for all internal memory management. alloc
Model of

Multiple Sorted Associative Container, Simple Associative Container

Type requirements

• Key is Assignable.

• Compare is a Strict Weak Ordering whose argument type is Key .

• Alloc is an Allocator.

Public base classes

None.

Members
Member Where defined Description
value_type Container The type of object, T , stored in the multiset.
key_type Associative Container The key type associated with value_type .
key_compare Sorted Associative Container Function object that compares two keys for ordering.
value_compare Sorted Associative Container Function object that compares two values for ordering.
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 multiset .
const_iterator Container Const iterator used to iterate through a multiset . ( Iterator and const_iterator are the same type.)
reverse_iterator Reversible Container Iterator used to iterate backwards through a multiset .
const_reverse_iterator Reversible Container Const iterator used to iterate backwards through a multiset . ( Reverse_iterator and const_reverse_iterator are the same type.)
iterator begin() const Container Returns an iterator pointing to the beginning of the multiset .
iterator end() const Container Returns an iterator pointing to the end of the multiset .
reverse_iterator rbegin() const Reversible Container Returns a reverse_iterator pointing to the beginning of the reversed multiset.
reverse_iterator rend() const Reversible Container Returns a reverse_iterator pointing to the end of the reversed multiset.
size_type size() const Container Returns the size of the multiset .
size_type max_size() const Container Returns the largest possible size of the multiset .
bool empty() const Container true if the multiset 's size is 0 .
key_compare key_comp() const Sorted Associative Container Returns the key_compare object used by the multiset .
value_compare value_comp() const Sorted Associative Container Returns the value_compare object used by the multiset .
multiset() Container Creates an empty multiset .
multiset(const key_compare& comp) Sorted Associative Container Creates an empty multiset , using comp as the key_compare object.
template multiset(InputIterator f, InputIterator l)[1] Multiple Sorted Associative Container Creates a multiset with a copy of a range.
template multiset(InputIterator f, InputIterator l, const key_compare& comp)[1] Multiple Sorted Associative Container Creates a multiset with a copy of a range, using comp as the key_compare object.
multiset(const multiset&) Container The copy constructor.
multiset& operator=(const multiset&) Container The assignment operator
void swap(multiset&) Container Swaps the contents of two multisets.
iterator insert(const value_type& x) Multiple Associative Container Inserts x into the multiset .
iterator insert(iterator pos, const value_type& x) Multiple Sorted Associative Container Inserts x into the multiset , using pos as a hint to where it will be inserted.
template void insert(InputIterator, InputIterator)[1] Multiple Sorted Associative Container Inserts a range into the multiset .
void erase(iterator pos) Associative Container Erases the element pointed to by pos .
size_type erase(const key_type& k) Associative Container Erases the element whose key is k .
void erase(iterator first, iterator last) Associative Container Erases all elements in a range.
void clear() Associative Container Erases all of the elements.
iterator find(const key_type& k) const Associative Container Finds an element whose key is k .
size_type count(const key_type& k) const Associative Container Counts the number of elements whose key is k .
iterator lower_bound(const key_type& k) const Sorted Associative Container Finds the first element whose key is not less than k .
iterator upper_bound(const key_type& k) const Sorted Associative Container Finds the first element whose key greater than k .
pair equal_range(const key_type& k) const Sorted Associative Container Finds a range containing all elements whose key is k .
bool operator==(const multiset&, const multiset&) Forward Container Tests two multisets for equality. This is a global function, not a member function.
bool operator<(const multiset&, const multiset&) Forward Container Lexicographical comparison. This is a global function, not a member function.
New members

All of multiset 's members are defined in the Multiple Sorted Associative Container and Simple Associative Container requirements. Multiset 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