Standard Template Library Programmer's Guide
Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Standard Template Library Programmer's Guide
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:4 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 80
- 1
- 2
- 3
- 4
- 5
Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
[6] The sort algorithm works only for random access iterators . In principle, however, it would be possible to write a sort algorithm that also accepted bidirectional iterators. Even if there were such a version of sort , it would still be useful for list 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.
Bidirectional Iterator, Reversible Container, Sequence, slist, vector .
slist
Category: containers
Component type: type
An slist is a singly linked list: a list where each element is linked to the next element, but not to the previous element. [1] That is, it is a Sequence that supports forward but not backward traversal, and (amortized) constant time insertion and removal of elements. Slist s, like list s, have the important property that insertion and splicing do not invalidate iterators to list elements, and that even removal invalidates only the iterators that point to the elements that are removed. The ordering of iterators may be changed (that is, slist::iterator might have a different predecessor or successor after a list operation than it did before), but the iterators themselves will not be invalidated or made to point to different elements unless that invalidation or mutation is explicit. [2]
The main difference between slist and list is that list 's iterators are bidirectional iterators, while slist 's iterators are forward iterators. This means that slist is less versatile than list ; frequently, however, bidirectional iterators are unnecessary. You should usually use slist unless you actually need the extra functionality of list , because singly linked lists are smaller and faster than double linked lists.
Important performance note: like every other Sequence, slist defines the member functions insert and erase . Using these member functions carelessly, however, can result in disastrously slow programs. The problem is that insert 's first argument is an iterator pos , and that it inserts the new element(s) beforepos . This means that insert must find the iterator just before pos ; this is a constant-time operation for list , since list has bidirectional iterators, but for slist it must find that iterator by traversing the list from the beginning up to pos . In other words: insert and erase are slow operations anywhere but near the beginning of the slist .
Slist provides the member functions insert_after and erase_after , which are constant time operations: you should always use insert_after and erase_after whenever possible. If you find that insert_after and erase_after aren't adequate for your needs, and that you often need to use insert and erase in the middle of the list, then you should probably use list instead of slist .
Defined in the header slist, and in the backward-compatibility header slist.h. The slist class, and the slist header, are an SGI extension; they are not part of the C++ standard.
int main() {
slist L;
L.push_front(0);
L.push_front(1);
L.insert_after(L.begin(), 2);
copy(L.begin(), L.end(), // The output is 1 2 0
ostream_iterator(cout, " "));
cout << endl;
slist::iterator back = L.previous(L.end());
back = L.insert_after(back, 3);
back = L.insert_after(back, 4);
back = L.insert_after(back, 5);
copy(L.begin(), L.end(), // The output is 1 2 0 3 4 5
ostream_iterator(cout, " "));
cout << endl;
}
Parameter | Description | Default |
---|---|---|
T |
The slist 's value type: the type of object that is stored in the list. | |
Alloc |
The slist 's allocator, used for all internal memory management. | alloc |
Front Insertion Sequence
None, except for those imposed by the requirements of Front Insertion Sequence.
None.
Member | Where defined | Description |
---|---|---|
value_type |
Container | The type of object, T , stored in the slist . |
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 an slist . |
const_iterator |
Container | Const iterator used to iterate through an slist . |
iterator begin() |
Container | Returns an iterator pointing to the beginning of the slist . |
iterator end() |
Container | Returns an iterator pointing to the end of the slist . |
const_iterator begin() const |
Container | Returns a const_iterator pointing to the beginning of the slist . |
const_iterator end() const |
Container | Returns a const_iterator pointing to the end of the slist . |
size_type size() const |
Container | Returns the size of the slist . Note: you should not assume that this function is constant time. It is permitted to be O(N ), where N is the number of elements in the slist . If you wish to test whether an slist is empty, you should write L.empty() rather than L.size() == 0 . |
size_type max_size() const |
Container | Returns the largest possible size of the slist . |
bool empty() const |
Container | true if the slist 's size is 0 . |
slist() |
Container | Creates an empty slist. |
slist(size_type n) |
Sequence | Creates an slist with n elements, each of which is a copy of T() . |
slist(size_type n, const T& t) |
Sequence | Creates an slist with n copies of t . |
slist(const slist&) |
Container | The copy constructor. |
template slist(InputIterator f, InputIterator l) [3] |
Sequence | Creates an slist with a copy of a range. |
~slist() |
Container | The destructor. |
slist& operator=(const slist&) |
Container | The assignment operator |
void swap(slist&) |
Container | Swaps the contents of two slists. |
reference front() |
Front Insertion Sequence | Returns the first element. |
const_reference front() const |
Front Insertion Sequence | Returns the first element. |
void push_front(const T&) |
Front Insertion Sequence | Inserts a new element at the beginning. |
void pop_front() |
Front Insertion Sequence | Removes the first element. |
iterator previous(iterator pos) |
slist |
See below |
const_iterator previous(const_iterator pos) |
slist |
See below |
iterator insert(iterator pos, const T& x) |
Sequence | Inserts x before pos . |
template void insert(iterator pos, InputIterator f, InputIterator l) [3] |
Sequence | Inserts the range [first, last) before pos . |
void insert(iterator pos, size_type n, const value_type& 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 . |
iterator insert_after(iterator pos) |
slist |
See below. |
iterator insert_after(iterator pos, const value_type& x) |
slist |
See below. |
template void insert_after(iterator pos, InputIterator f, InputIterator l) |
slist |
See below. |
void insert_after(iterator pos, size_type n, const value_type& x) |
slist |
See below. |
iterator erase_after(iterator pos) |
slist |
See below. |
iterator erase_after(iterator before_first, iterator last) |
slist |
See below. |
void splice(iterator position, slist& L) |
slist |
See below. |
void splice(iterator position, slist& L, iterator i) |
slist |
See below. |
void splice(iterator position, slist& L, iterator f, iterator l) |
slist |
See below. |
void splice_after(iterator pos, iterator prev) |
slist |
See below. |
void splice_after(iterator pos, iterator before_first, iterator before_last) |
slist |
See below. |
void remove(const T& value) |
slist |
See below. |
void unique() |
slist |
See below. |
void merge(slist& L) |
slist |
See below. |
void sort() |
slist |
See below. |
bool operator==(const slist&, const slist&) |
Forward Container | Tests two slists for equality. This is a global function, not a member function. |
bool operator<(const slist&, const slist&) |
Forward Container | Lexicographical comparison. This is a global function, not a member function. |
These members are not defined in the Front Insertion Sequence requirements, but are specific to slist :
Читать дальшеИнтервал:
Закладка:
Похожие книги на «Standard Template Library Programmer's Guide»
Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.