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.

See also

stack, queue, set, make_heap, push_heap, pop_heap, is_heap, sort, is_sorted, Container, Sorted Associative Container, Sequence

bitset<N>

Category: containers

Component type: type

Description

Bitset is very similar to vector<bool> (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<bool>. 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.

Example

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;

 }

}

Definition

Defined in the standard header bitset.

Template parameters
Parameter Description
N A nonzero constant of type size_t : the number of bits that the bitset contains.
Model of

Assignable, Default Constructible, Equality Comparable

Type requirements

N is a constant integer expression of a type convertible to size_t, and N is a positive number.

Public base classes

None.

Members
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.
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату