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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
[2] This restriction is the only reason for priority_queue to exist at all. If iteration through elements is important, you can either use a vector that is maintained in sorted order, or a set , or a vector that is maintained as a heap using make_heap , push_heap , and pop_heap . Priority_queue is, in fact, implemented as a random access container that is maintained as a heap. The only reason to use the container adaptor priority_queue , instead of performing the heap operations manually, is to make it clear that you are never performing any operations that might violate the heap invariant.
[3] One might wonder why pop() returns void , instead of value_type . That is, why must one use top() and pop() to examine and remove the element at the top of the priority_queue , instead of combining the two in a single member function? In fact, there is a good reason for this design. If pop() returned the top element, it would have to return by value rather than by reference: return by reference would create a dangling pointer. Return by value, however, is inefficient: it involves at least one redundant copy constructor call. Since it is impossible for pop() to return a value in such a way as to be both efficient and correct, it is more sensible for it to return no value at all and to require clients to use top() to inspect the value at the top of the priority_queue .
stack , queue , set , make_heap , push_heap , pop_heap , is_heap , sort , is_sorted, Container, Sorted Associative Container, Sequence
bitset
Category: containers
Component type: type
Bitset is very similar to vector (also known as bit_vector): it contains a collection of bits, and provides constant-time access to each bit. There are two main differences between bitset and vector . First, the size of a bitset cannot be changed: bitset 's template parameter N , which specifies the number of bits in the bitset, must be an integer constant. Second, bitset is not a Sequence; in fact, it is not an STL Container at all. It does not have iterators, for example, or begin() and end() member functions. Instead, bitset 's interface resembles that of unsigned integers. It defines bitwise arithmetic operators such as &= , |= , and ^= .
In general, bit 0 is the least significant bit and bit N-1 is the most significant bit.
int main() {
const bitset<12> mask(2730ul);
cout << "mask = " << mask << endl;
bitset<12> x;
cout << "Enter a 12-bit bitset in binary: " << flush;
if (cin >> x) {
cout << "x = " << x << endl;
cout << "As ulong: " << x.to_ulong() << endl;
cout << "And with mask: " << (x & mask) << endl;
cout << "Or with mask: " << (x | mask) << endl;
}
}
Defined in the standard header bitset.
Parameter | Description |
---|---|
N |
A nonzero constant of type size_t : the number of bits that the bitset contains. |
Assignable, Default Constructible, Equality Comparable
N is a constant integer expression of a type convertible to size_t , and N is a positive number.
None.
Member | Where defined | Description |
---|---|---|
reference |
bitset |
A proxy class that acts as a reference to a single bit. |
bitset() |
Default Constructible | The default constructor. All bits are initially zero. |
bitset(unsigned long val) |
bitset |
Conversion from unsigned long. |
bitset(const bitset&) |
Assignable | Copy constructor. |
bitset& operator=(const bitset&) |
Assignable | Assignment operator. |
template explicit bitset(const basic_string& s, size_t pos = 0, size_t n = basic_string ::npos) |
bitset |
Conversion from string. |
bitset& operator&=(const bitset&) |
bitset |
Bitwise and. |
bitset& operator|=(const bitset&) |
bitset |
Bitwise inclusive or. |
bitset& operator^=(const bitset&) |
bitset |
Bitwise exclusive or. |
bitset& operator<<=(size_t) |
bitset |
Left shift. |
bitset& operator>>=(size_t) |
bitset |
Right shift. |
bitset operator<<(size_t n) const |
bitset |
Returns a copy of *this shifted left by n bits. |
bitset operator>>(size_t n) const |
bitset |
Returns a copy of *this shifted right by n bits. |
bitset& set() |
bitset |
Sets every bit. |
bitset& flip() |
bitset |
Flips the value of every bit. |
bitset operator~() const |
bitset |
Returns a copy of *this with all of its bits flipped. |
bitset& reset() |
bitset |
Clears every bit. |
bitset& set(size_t n, int val = 1) |
bitset |
Sets bit n if val is nonzero, and clears bit n if val is zero. |
bitset& reset(size_t n) |
bitset |
Clears bit n . |
bitset flip(size_t n) |
bitset |
Flips bit n . |
size_t size() const |
bitset |
Returns N . |
size_t count() const |
bitset |
Returns the number of bits that are set. |
bool any() const |
bitset |
Returns true if any bits are set. |
bool none() const |
bitset |
Returns true if no bits are set. |
bool test(size_t n) const |
bitset |
Returns true if bit n is set. |
reference operator[](size_t n) |
bitset |
Returns a reference to bit n . |
bool operator[](size_t n) const |
bitset |
Returns true if bit n is set. |
unsigned long to_ulong() const |
bitset |
Returns an unsigned long corresponding to the bits in *this . |
template basic_string to_string() const |
bitset |
Returns a string representation of *this . |
bool operator==(const bitset&) const |
Equality Comparable | The equality operator. |
bool operator!=(const bitset&) const |
Equality Comparable | The inequality operator. |
bitset operator&(const bitset&, const bitset&) |
bitset |
Bitwise and of two bitsets. This is a global function, not a member function. |
bitset operator|(const bitset&, const bitset&) |
bitset |
Bitwise or of two bitsets. This is a global function, not a member function. |
bitset operator^(const bitset&, const bitset&) |
bitset |
Bitwise exclusive or of two bitsets. This is a global function, not a member function. |
template basic_istream& operator>>(basic_istream&, bitset&) |
bitset |
Extract a bitset from an input stream. |
template basic_ostream& operator>>(basic_ostream&, const bitset&) |
bitset |
Output a bitset to an output stream. |
These members are not defined in the Assignable, Default Constructible, or Equality Comparable requirements, but are specific to bitset .
Читать дальшеИнтервал:
Закладка:
Похожие книги на «Standard Template Library Programmer's Guide»
Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.