-1- This clause describes components that C++ programs may use to organize collections of information.
-2- The following subclauses describe container requirements, and components for sequences and associative containers, as summarized in Table ??:
Subclause | Header(s) |
lib.container.requirements Requirements | |
lib.sequences Sequences | <deque> |
<list> | |
<queue> | |
<stack> | |
<vector> | |
lib.associative Associative containers | <map> |
<set> | |
lib.template.bitset bitset | <bitset> |
23.1 - Container requirements [lib.container.requirements]
-1- Containers are objects that store other objects. They control allocation and deallocation of these objects through constructors, destructors, insert and erase operations.
-2- All of the complexity requirements in this clause are stated solely in terms of the number of operations on the contained objects. [Example: the copy constructor of type vector <vector<int> > has linear complexity, even though the complexity of copying each contained vector<int> is itself linear. ]
-3- The type of objects stored in these components must meet the requirements of CopyConstructible types (lib.copyconstructible), and the additional requirements of Assignable types.
-4- In Table ??, T is the type used to instantiate the container, t is a value of T, and u is a value of (possibly const) T.
expression | return type | post-condition |
t = u | T& | t is equivalent to u |
-5- In Tables ?? and ??, X denotes a container class containing objects of type T, a and b denote values of type X, u denotes an identifier and r denotes a value of X&.
expression | return type | assertion/note | complexity |
pre/post-condition | |||
X::value_type | T | T is Assignable | compile time |
X::reference | lvalue of T | compile time | |
X::const_reference | const lvalue of T | compile time | |
X::iterator | iterator type pointing to T |
any iterator category
except output iterator.
convertible to X::const_iterator. | compile time |
X::const_iterator | iterator type pointing to const T | any iterator category except output iterator. | compile time |
X::difference_type | signed integral type | is identical to the difference type of X::iterator and X::const_iterator | compile time |
X::size_type | unsigned integral type | size_type can represent any non-negative value of difference_type | compile time |
X u; | post: u.size() == 0 . | constant | |
X(); | X().size() == 0 . | constant | |
X(a); | a == X(a) . | linear | |
X u(a); | post: u == a . | linear | |
X u = a; | Equivalent to: X u; u = a; | ||
(&a)->~X(); | void | note: the destructor is applied to every element of a ; all the memory is deallocated. | linear |
a.begin(); | iterator ; | constant | |
const_iterator | |||
for constant a | |||
a.end(); | iterator ; | constant | |
const_iterator | |||
for constant a | |||
a == b | convertible to bool | == is an equivalence relation. | linear |
a.size()==b.size() | |||
&& equal(a.begin(), | |||
a.end(), b.begin()) | |||
a != b | convertible to bool | Equivalent to: !(a == b) | linear |
a.swap(b); | void | swap(a,b) | (Note A) |
expression | return type | operational | assertion/note | complexity |
semantics | pre/post-condition | |||
r = a | X& | post: r == a . | linear | |
a.size() | size_type | a.end()-a.begin() | (Note A) | |
a.max_size() | size_type | size() of the largest possible container. | (Note A) | |
a.empty() | convertible to bool | a.size() == 0 | constant | |
a < b | convertible to bool | lexicographical_compare (a.begin(), a.end(), b.begin(), b.end()) | pre: < is defined for values of T . < is a total ordering relation. | linear |
a > b | convertible to bool | b < a | linear | |
a <= b | convertible to bool | !(a > b) | linear | |
a >= b | convertible to bool | !(a < b) | linear |
Notes: the algorithms swap(), equal() and lexicographical_compare() are defined in clause lib.algorithms. Those entries marked ``(Note A)'' should have constant complexity.
-6- The member function size() returns the number of elements in the container. Its semantics is defined by the rules of constructors, inserts, and erases.
-7- begin() returns an iterator referring to the first element in the container. end() returns an iterator which is the past-the-end value for the container. If the container is empty, then begin() == end();
-8- Copy constructors for all container types defined in this clause copy an allocator argument from their respective first parameters. All other constructors for these container types take an Allocator& argument (lib.allocator.requirements), an allocator whose value type is the same as the container's value type. A copy of this argument is used for any memory allocation performed, by these constructors and by all member functions, during the lifetime of each container object. In all container types defined in this clause, the member get_allocator() returns a copy of the Allocator object used to construct the container.
-9- If the iterator type of a container belongs to the bidirectional or random access iterator categories (lib.iterator.requirements), the container is called reversible and satisfies the additional requirements in Table ??:
expression | return type | assertion/note | complexity |
pre/post-condition | |||
X::reverse_ iterator | iterator type pointing to T | reverse_iterator <iterator> | compile time |
X::const_
reverse_ iterator | iterator type pointing to const T | reverse_iterator <const_iterator> | compile time |
a.rbegin() | reverse_iterator ; const_reverse_iterator for constant a | reverse_iterator(end()) | constant |
a.rend() | reverse_iterator ; const_reverse_iterator for constant a | reverse_iterator(begin()) | constant |
-10- Unless otherwise specified (see lib.deque.modifiers and lib.vector.modifiers) all container types defined in this clause meet the following additional requirements:
-1- A sequence is a kind of container that organizes a finite set of objects, all of the same type, into a strictly linear arrangement. The library provides three basic kinds of sequence containers: vector, list, and deque. It also provides container adaptors that make it easy to construct abstract data types, such as stacks or queues, out of the basic sequence kinds (or out of other kinds of sequences that the user might define).
-2- vector, list, and deque offer the programmer different complexity trade-offs and should be used accordingly. vector is the type of sequence that should be used by default. list should be used when there are frequent insertions and deletions from the middle of the sequence. deque is the data structure of choice when most insertions and deletions take place at the beginning or at the end of the sequence.
-3- In Tables ?? and ??, X denotes a sequence class, a denotes a value of X, i and j denote iterators satisfying input iterator requirements, [i, j) denotes a valid range, n denotes a value of X::size_type, p and q2 denote valid iterators to a, q and q1 denote valid dereferenceable iterators to a, [q1, q2) denotes a valid range, and t denotes a value of X::value_type.
-4- The complexities of the expressions are sequence dependent.
expression | return type | assertion/note |
pre/post-condition | ||
X(n, t) | post: size() == n . | |
X a(n, t); | constructs a sequence with n copies of t . | |
X(i, j) | post: size() == distance between i and j . | |
X a(i, j); | constructs a sequence equal to the range [i,j) . | |
a.insert(p,t) | iterator | inserts a copy of t before p . |
a.insert(p,n,t) | void | inserts n copies of t before p . |
a.insert(p,i,j) | void |
pre: i,j are not iterators into a.
inserts copies of elements in [i,j) before p . |
a.erase(q) | iterator | erases the element pointed to by q . |
a.erase(q1,q2) | iterator | erases the elements in the range [q1,q2) . |
a.clear() | void |
erase(begin(), end())
post: size() == 0. |
-5- iterator and const_iterator types for sequences must be at least of the forward iterator category.
-6- The iterator returned from a.insert(p,t) points to the copy of t inserted into a.
-7- The iterator returned from a.erase(q) points to the element immediately following q prior to the element being erased. If no such element exists, a.end() is returned.
-8- The iterator returned by a.erase(q1,q2) points to the element pointed to by q2 prior to any elements being erased. If no such element exists, a.end() is returned.
-9- For every sequence defined in this clause and in clause lib.strings:
shall have the same effect as:template <class InputIterator> X(InputIterator f, InputIterator l, const Allocator& a = Allocator())
if InputIterator is an integral type.X(static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l), a)
shall have the same effect, respectively, as:template <class InputIterator> //such as insert() rt fx1(iterator p, InputIterator f, InputIterator l); template <class InputIterator> // such as append(), assign() rt fx2(InputIterator f, InputIterator l); template <class InputIterator> // such as replace() rt fx3(iterator i1, iteraror i2, InputIterator f, InputIterator l);
if InputIterator is an integral type.fx1(p, static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l)); fx2(static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l)); fx3(i1, i2, static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l));
-10- [Note: This follows directly from the requirements in the Iterator Requirements Table. Integral types cannot be iterators, so, if n1 and n2 are values of an integral type N, the expression X(n1, n2) cannot possibly be interpreted as construction from a range of iterators. It must be taken to mean the first constructor in the Iterator Requirements Table, not the second one. If there is no conversion from N to X::value_type, then this is not a valid expression at all.
-11-
One way that sequence implementors can satisfy this requirement is to
specialize the member template for every integral type.
Less cumbersome implementation techniques also exist.
--- end note]
[Example:
list<int> x; ... vector<int> y(x.begin(), x.end()); //Construct a vector // from a range of iterators. vector<int> z(100, 1); // Construct a vector of 100 // elements, all initialized // to 1. The arguments are // not interpreted as iterators. z.insert(z.begin(), x.begin(), x.end());// Insert a range of // iterators. z.insert(z.begin(), 20, 0); // Insert 20 copies of the // number 0.
-12- The operations in Table ?? are provided only for the containers for which they take constant time:
expression | return type | operational | container |
semantics | |||
a.front() | reference; const_reference for constant a | *a.begin() | vector, list, deque |
a.back() | reference; const_reference for constant a | *--a.end() | vector, list, deque |
a.push_front(x) | void | a.insert(a.begin(),x) | list, deque |
a.push_back(x) | void | a.insert(a.end(),x) | vector, list, deque |
a.pop_front() | void | a.erase(a.begin()) | list, deque |
a.pop_back() | void | a.erase(--a.end()) | vector, list, deque |
a[n] | reference; const_reference for constant a | *(a.begin() + n) | vector, deque |
a.at(n) | reference; const_reference for constant a | *(a.begin() + n) | vector, deque |
-13-
The member function
at()
provides bounds-checked access to container elements.
at()
throws
out_of_range
if
n >= a.size().
23.1.2 - Associative containers [lib.associative.reqmts]
-1- Associative containers provide an ability for fast retrieval of data based on keys. The library provides four basic kinds of associative containers: set, multiset, map and multimap.
-2- Each associative container is parameterized on Key and an ordering relation Compare that induces a strict weak ordering (lib.alg.sorting) on elements of Key. In addition, map and multimap associate an arbitrary type T with the Key. The object of type Compare is called the comparison object of a container. This comparison object may be a pointer to function or an object of a type with an appropriate function call operator.
-3- The phrase ``equivalence of keys'' means the equivalence relation imposed by the comparison and not the operator== on keys. That is, two keys k1 and k2 are considered to be equivalent if for the comparison object comp, comp(k1, k2) == false && comp(k2, k1) == false.
-4- An associative container supports unique keys if it may contain at most one element for each key. Otherwise, it supports equivalent keys. set and map support unique keys. multiset and multimap support equivalent keys.
-5- For set and multiset the value type is the same as the key type. For map and multimap it is equal to pair<const Key, T>.
-6- iterator of an associative container is of the bidirectional iterator category.
-7- In Table ??, X is an associative container class, a is a value of X, a_uniq is a value of X when X supports unique keys, and a_eq is a value of X when X supports multiple keys, i and j satisfy input iterator requirements and refer to elements of value_type, [i, j) is a valid range, p and q2 are valid iterators to a, q and q1 are valid dereferenceable iterators to a, [q1, q2) is a valid range, t is a value of X::value_type, k is a value of X::key_type and c is a value of type X::key_compare.
expression | return type | assertion/note | complexity |
pre/post-condition | |||
X::key_type | Key | Key is Assignable | compile time |
X::key_compare | Compare | defaults to less<key_type> | compile time |
X:: value_compare | a binary predicate type | is the same as key_compare for set and multiset ; is an ordering relation on pairs induced by the first component (i.e. Key ) for map and multimap . | compile time |
X(c) | constructs an empty container; | constant | |
X a(c); | uses c as a comparison object | ||
X() | constructs an empty container; | constant | |
X a; | uses Compare() as a comparison object | ||
X(i,j,c);
X a(i,j,c); | constructs an empty container and inserts elements from the range [i, j) into it; uses c as a comparison object |
NlogN in general
( N is the distance from
i to j );
linear if [i, j) is sorted with value_comp() | |
X(i, j) | same as above, but uses Compare() as a comparison object. | same as above | |
X a(i, j); | |||
a.key_comp() | X::key_compare | returns the comparison object out of which a was constructed. | constant |
a.value_comp() | X:: value_compare | returns an object of value_compare constructed out of the comparison object | constant |
a_uniq. insert(t) | pair<iterator, bool> | inserts t if and only if there is no element in the container with key equivalent to the key of t . The bool component of the returned pair indicates whether the insertion takes place and the iterator component of the pair points to the element with key equivalent to the key of t . | logarithmic |
a_eq.insert(t) | iterator | inserts t and returns the iterator pointing to the newly inserted element. | logarithmic |
expression | return type | assertion/note | complexity |
pre/post-condition | |||
a.insert(p,t) | iterator | inserts t if and only if there is no element with key equivalent to the key of t in containers with unique keys; always inserts t in containers with equivalent keys. always returns the iterator pointing to the element with key equivalent to the key of t . iterator p is a hint pointing to where the insert should start to search. | logarithmic in general, but amortized constant if t is inserted right after p . |
a.insert(i,j) | void |
pre: i,j are not iterators into a.
inserts each element from the range [i, j) if and only if there is no element with key equivalent to the key of that element in containers with unique keys; always inserts that element in containers with equivalent keys. |
Nlog(size()+N)
( N is the distance from
i to j )
in general;
linear if [i, j) is sorted according to value_comp() |
a.erase(k) | size_type | erases all the elements in the container with key equivalent to k . returns the number of erased elements. | log(size()) + count(k) |
a.erase(q) | void | erases the element pointed to by q . | amortized constant |
a.erase(q1,q2) | void | erases all the elements in the range [q1, q2) . | log(size())+ N where N is the distance from q1 to q2 . |
a.clear() | void |
erase(a.begin(), a.end()))
post: size == 0 | log(size()) + N |
a.find(k) | iterator ; const_iterator for constant a | returns an iterator pointing to an element with the key equivalent to k , or a.end() if such an element is not found. | logarithmic |
a.count(k) | size_type | returns the number of elements with key equivalent to k | log(size()) + count(k) |
a.lower_bound(k) | iterator ; const_iterator for constant a | returns an iterator pointing to the first element with key not less than k . | logarithmic |
a.upper_bound(k) | iterator ; const_iterator for constant a | returns an iterator pointing to the first element with key greater than k . | logarithmic |
a.equal_range(k) | pair< iterator,iterator> ; pair< const_iterator, const_iterator> for constant a | equivalent to make_pair( a.lower_bound(k), a.upper_bound(k)) . | logarithmic |
-8- The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
-9- The fundamental property of iterators of associative containers is that they iterate through the containers in the non-descending order of keys where non-descending is defined by the comparison that was used to construct them. For any two dereferenceable iterators i and j such that distance from i to j is positive,
value_comp(*j, *i) == false
-10- For associative containers with unique keys the stronger condition holds,
value_comp(*i, *j) != false.
-11-
When an associative container is constructed by passing a comparison object the
container shall not store a pointer or reference to the passed object,
even if that object is passed by reference.
When an associative container is copied, either through a copy constructor
or an assignment operator,
the target container shall then use the comparison object from the container
being copied,
as if that comparison object had been passed to the target container in
its constructor.
23.2 - Sequences [lib.sequences]
-1-
Headers
<deque>,
<list>,
<queue>,
<stack>,
and
<vector>.
Header <deque> synopsis
namespace std { template <class T, class Allocator = allocator<T> > class deque; template <class T, class Allocator> bool operator== (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator!= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator>= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator<= (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> void swap(deque<T,Allocator>& x, deque<T,Allocator>& y); }
Header <list> synopsis
namespace std { template <class T, class Allocator = allocator<T> > class list; template <class T, class Allocator> bool operator==(const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> bool operator< (const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> bool operator!=(const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> bool operator> (const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> bool operator>=(const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> bool operator<=(const list<T,Allocator>& x, const list<T,Allocator>& y); template <class T, class Allocator> void swap(list<T,Allocator>& x, list<T,Allocator>& y); }
Header <queue> synopsis
namespace std { template <class T, class Container = deque<T> > class queue; template <class T, class Container> bool operator==(const queue<T, Container>& x, const queue<T, Container>& y); template <class T, class Container> bool operator< (const queue<T, Container>& x, const queue<T, Container>& y); template <class T, class Container> bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y); template <class T, class Container> bool operator> (const queue<T, Container>& x, const queue<T, Container>& y); template <class T, class Container> bool operator>=(const queue<T, Container>& x, const queue<T, Container>& y); template <class T, class Container> bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);
template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> > class priority_queue; }
Header <stack> synopsis
namespace std { template <class T, class Container = deque<T> > class stack; template <class T, class Container> bool operator==(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator< (const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator> (const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y); template <class T, class Container> bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y); }
Header <vector> synopsis
namespace std { template <class T, class Allocator = allocator<T> > class vector; template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); template <class T, class Allocator> void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);
template <class Allocator> class vector<bool,Allocator>; template <class Allocator> bool operator==(const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> bool operator< (const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> bool operator!=(const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> bool operator> (const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> bool operator>=(const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> bool operator<=(const vector<bool,Allocator>& x, const vector<bool,Allocator>& y); template <class Allocator> void swap(vector<bool,Allocator>& x, vector<bool,Allocator>& y); }
-1- A deque is a kind of sequence that, like a vector (lib.vector), supports random access iterators. In addition, it supports constant time insert and erase operations at the beginning or the end; insert and erase in the middle take linear time. That is, a deque is especially optimized for pushing and popping elements at the beginning and end. As with vectors, storage management is handled automatically.
-2- A deque satisfies all of the requirements of a container and of a reversible container (given in tables in lib.container.requirements) and of a sequence, including the optional sequence requirements (lib.sequence.reqmts). Descriptions are provided here only for operations on deque that are not described in one of these tables or for operations where there is additional semantic information.
namespace std { template <class T, class Allocator = allocator<T> > class deque { public: //types: typedef typename Allocator::reference reference; typedef typename Allocator::const_reference const_reference; typedef implementation defined iterator; // See lib.container.requirements typedef implementation defined const_iterator; // See lib.container.requirements typedef implementation defined size_type; // See lib.container.requirements typedef implementation defined difference_type; // See lib.container.requirements typedef T value_type; typedef Allocator allocator_type; typedef typename Allocator::pointer pointer; typedef typename Allocator::const_pointer const_pointer; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//lib.deque.cons construct/copy/destroy: explicit deque(const Allocator& = Allocator()); explicit deque(size_type n, const T& value = T(), const Allocator& = Allocator()); template <class InputIterator> deque(InputIterator first, InputIterator last, const Allocator& = Allocator()); deque(const deque<T,Allocator>& x); ~deque(); deque<T,Allocator>& operator=(const deque<T,Allocator>& x); template <class InputIterator> void assign(InputIterator first, InputIterator last); void assign(size_type n, const T& t); allocator_type get_allocator() const;
//iterators: iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const;
//lib.deque.capacity capacity: size_type size() const; size_type max_size() const; void resize(size_type sz, T c = T()); bool empty() const;
//element access: reference operator[](size_type n); const_reference operator[](size_type n) const; reference at(size_type n); const_reference at(size_type n) const; reference front(); const_reference front() const; reference back(); const_reference back() const;
//lib.deque.modifiers modifiers: void push_front(const T& x); void push_back(const T& x);
iterator insert(iterator position, const T& x); void insert(iterator position, size_type n, const T& x); template <class InputIterator> void insert (iterator position, InputIterator first, InputIterator last);
void pop_front(); void pop_back();
iterator erase(iterator position); iterator erase(iterator first, iterator last); void swap(deque<T,Allocator>&); void clear(); };
template <class T, class Allocator> bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); template <class T, class Allocator> bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
//specialized algorithms: template <class T, class Allocator> void swap(deque<T,Allocator>& x, deque<T,Allocator>& y); }
explicit deque(const Allocator& = Allocator());
-1- Effects: Constructs an empty deque, using the specified allocator.
-2- Complexity:
Constant.
explicit deque(size_type n, const T& value = T(),
const Allocator& = Allocator());
-3- Effects: Constructs a deque with n copies of value, using the specified allocator.
-4- Complexity:
Linear in n.
template <class InputIterator>
deque(InputIterator first, InputIterator last,
const Allocator& = Allocator());
-5- Effects: Constructs a deque equal to the the range [first, last), using the specified allocator.
-6- Complexity: If the iterators first and last are forward iterators, bidirectional iterators, or random access iterators the constructor makes only N calls to the copy constructor, and performs no reallocations, where N is last - first. It makes at most 2N calls to the copy constructor of T and log N reallocations if they are input iterators.*
[Footnote: The complexity is greater in the case of input iterators because each element must be added individually: it is impossible to determine the distance between first abd last before doing the copying. --- end foonote]
template <class InputIterator> void assign(InputIterator first, InputIterator last);
-7- Effects:
erase(begin(), end()); insert(begin(), first, last);
void assign(size_type n, const T& t);
-8- Effects:
erase(begin(), end()); insert(begin(), n, t);
void resize(size_type sz, T c = T());
-1- Effects:
if (sz > size()) insert(end(), sz-size(), c); else if (sz < size()) erase(begin()+sz, end()); else ; //do nothing
iterator insert(iterator position, const T& x); void insert(iterator position, size_type n, const T& x); template <class InputIterator> void insert(iterator position, InputIterator first, InputIterator last);
-1- Effects: An insert in the middle of the deque invalidates all the iterators and references to elements of the deque. An insert at either end of the deque invalidates all the iterators to the deque, but has no effect on the validity of references to elements of the deque.
-2- Notes: If an exception is thrown other than by the copy constructor or assignment operator of T there are no effects.
-3- Complexity:
In the worst case, inserting a single element
into a deque takes time linear in the minimum of the distance from the insertion point to the beginning of
the deque and the distance from the insertion point to the end of the deque.
Inserting a single element either at the beginning or end of a deque always takes constant time
and causes a single call to the copy constructor of
T.
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
-4- Effects: An erase in the middle of the deque invalidates all the iterators and references to elements of the deque. An erase at either end of the deque invalidates only the iterators and the references to the erased elements.
-5- Complexity: The number of calls to the destructor is the same as the number of elements erased, but the number of the calls to the assignment operator is at most equal to the minimum of the number of elements before the erased elements and the number of elements after the erased elements.
-6- Throws:
Nothing unless an exception is thrown by the copy constructor or assignment operator of
T.
23.2.1.4 - deque specialized algorithms [lib.deque.special]
template <class T, class Allocator>
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y);
-1- Effects:
x.swap(y);
-1- A list is a kind of sequence that supports bidirectional iterators and allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Unlike vectors (lib.vector) and deques (lib.deque), fast random access to list elements is not supported, but many algorithms only need sequential access anyway.
-2- A list satisfies all of the requirements of a container and of a reversible container (given in two tables in lib.container.requirements) and of a sequence, including most of the the optional sequence requirements (lib.sequence.reqmts). The exceptions are the operator[] and at member functions, which are not provided.*
[Footnote: These member functions are only provided by containers whose iterators are random access iterators. --- end foonote]Descriptions are provided here only for operations on list that are not described in one of these tables or for operations where there is additional semantic information.
namespace std { template <class T, class Allocator = allocator<T> > class list { public: //types: typedef typename Allocator::reference reference; typedef typename Allocator::const_reference const_reference; typedef implementation defined iterator; // See lib.container.requirements typedef implementation defined const_iterator; // See lib.container.requirements typedef implementation defined size_type; // See lib.container.requirements typedef implementation defined difference_type;// See lib.container.requirements typedef T value_type; typedef Allocator allocator_type; typedef typename Allocator::pointer pointer; typedef typename Allocator::const_pointer const_pointer; typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//lib.list.cons construct/copy/destroy: explicit list(const Allocator& = Allocator()); explicit list(size_type n , const T& value = T(), const Allocator& = Allocator()); template <class InputIterator> list(InputIterator first , InputIterator last , const Allocator& = Allocator()); list(const list<T,Allocator>& x ); ~list(); list<T,Allocator>& operator=(const list<T,Allocator>& x ); template <class InputIterator> void assign(InputIterator first, InputIterator last); void assign(size_type n, const T& t); allocator_type get_allocator() const;
//iterators: iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const;
//lib.list.capacity capacity: bool empty() const; size_type size() const; size_type max_size() const; void resize(size_type sz, T c = T());
//element access: reference front(); const_reference front() const; reference back(); const_reference back() const;
//lib.list.modifiers modifiers: void push_front(const T& x ); void pop_front(); void push_back(const T& x ); void pop_back();
iterator insert(iterator position , const T& x ); void insert(iterator position , size_type n , const T& x ); template <class InputIterator> void insert(iterator position , InputIterator first , InputIterator last );
iterator erase(iterator position ); iterator erase(iterator position , iterator last ); void swap(list<T,Allocator>&); void clear();
//lib.list.ops list operations: void splice(iterator position , list<T,Allocator>& x ); void splice(iterator position , list<T,Allocator>& x , iterator i ); void splice(iterator position , list<T,Allocator>& x , iterator first , iterator last );
void remove(const T& value ); template <class Predicate> void remove_if(Predicate pred );
void unique(); template <class BinaryPredicate> void unique(BinaryPredicate binary_pred );
void merge(list<T,Allocator>& x ); template <class Compare> void merge(list<T,Allocator>& x , Compare comp );
void sort(); template <class Compare> void sort(Compare comp );
void reverse(); };
template <class T, class Allocator> bool operator==(const list<T,Allocator>& x , const list<T,Allocator>& y ); template <class T, class Allocator> bool operator< (const list<T,Allocator>& x , const list<T,Allocator>& y ); template <class T, class Allocator> bool operator!=(const list<T,Allocator>& x , const list<T,Allocator>& y ); template <class T, class Allocator> bool operator> (const list<T,Allocator>& x , const list<T,Allocator>& y ); template <class T, class Allocator> bool operator>=(const list<T,Allocator>& x , const list<T,Allocator>& y ); template <class T, class Allocator> bool operator<=(const list<T,Allocator>& x , const list<T,Allocator>& y );
//specialized algorithms: template <class T, class Allocator> void swap(list<T,Allocator>& x, list<T,Allocator>& y); }
explicit list(const Allocator& = Allocator());
-1- Effects: Constructs an empty list, using the specified allocator.
-2- Complexity:
Constant.
explicit list(size_type n, const T& value = T(),
const Allocator& = Allocator());
-3- Effects: Constructs a list with n copies of value, using the specified allocator.
-4- Complexity:
Linear in
n.
template <class InputIterator>
list(InputIterator first, InputIterator last,
const Allocator& = Allocator());
-5- Effects: Constructs a list equal to the range [first, last).
-6- Complexity:
Linear in
first - last.
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
-7- Effects:
erase(begin(), end()); insert(begin(), first, last);
void assign(size_type n, const T& t);
-8- Effects:
erase(begin(), end()); insert(begin(), n, t);
void resize(size_type sz, T c = T());
-1- Effects:
if (sz > size()) insert(end(), sz-size(), c); else if (sz < size()) erase(begin()+sz, end()); else ; //do nothing
iterator insert(iterator position , const T& x ); void insert(iterator position , size_type n , const T& x ); template <class InputIterator> void insert(iterator position , InputIterator first , InputIterator last );
void push_front(const T& x); void push_back(const T& x);
-1- Notes: Does not affect the validity of iterators and references. If an exception is thrown there are no effects.
-2- Complexity:
Insertion of a single element into a list takes constant time and exactly one call to the copy constructor of
T.
Insertion of multiple elements into a list is
linear in the number of elements inserted, and the number of calls to the copy constructor of
T
is exactly equal to the number of elements inserted.
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
void pop_front();
void pop_back();
void clear();
-3- Effects: Invalidates only the iterators and references to the erased elements.
-4- Throws: Nothing.
-5- Complexity:
Erasing a single element is a constant time operation with a single call to the destructor of
T.
Erasing a range in a list is linear time in the
size of the range and the number of calls to the destructor of type
T
is exactly equal to the size of the range.
23.2.2.4 - list operations [lib.list.ops]
-1- Since lists allow fast insertion and erasing from the middle of a list, certain operations are provided specifically for them.
-2-
list
provides three splice operations that destructively move elements from one list to another.
void splice(iterator position , list<T,Allocator>& x );
-3- Requires: &x != this.
-4- Effects: Inserts the contents of x before position and x becomes empty. Invalidates all iterators and references to the list x.
-5- Throws: Nothing
-6- Complexity:
Constant time.
void splice(iterator position , list<T,Allocator>& x , iterator i );
-7- Effects: Inserts an element pointed to by i from list x before position and removes the element from x. The result is unchanged if position == i or position == ++i. Invalidates only the iterators and references to the spliced element.
-8- Throws: Nothing
-9- Requires: i is a valid dereferenceable iterator of x.
-10- Complexity:
Constant time.
void splice(iterator position , list<T,Allocator>& x , iterator first ,
iterator last );
-11- Effects: Inserts elements in the range [first, last) before position and removes the elements from x.
-12- Requires: [first, last) is a valid range in x. The result is undefined if position is an iterator in the range [first, last). Invalidates only the iterators and references to the spliced elements.
-13- Throws: Nothing
-14- Complexity:
Constant time if
&x == this;
otherwise, linear time.
void remove(const T& value );
template <class Predicate> void remove_if(Predicate pred );
-15- Effects: Erases all the elements in the list referred by a list iterator i for which the following conditions hold: *i == value, pred(*i) != false.
-16- Throws: Nothing unless an exception is thrown by *i == value or pred(*i) != false.
-17- Notes: Stable: the relative order of the elements that are not removed is the same as their relative order in the original list.
-18- Complexity:
Exactly
size()
applications of the corresponding predicate.
void unique();
template <class BinaryPredicate> void unique(BinaryPredicate binary_pred );
-19- Effects:
Eliminates all but the first element from every
consecutive group of equal elements referred to by the
iterator
i
in the range
[first + 1, last)
for which
*i == *(i-1)
(for the version of
unique
with no arguments) or
pred(*i, *(i - 1))
(for the version of
unique
with a predicate argument)
holds.
-1- Effects:
-1-
The container adaptors each take a Container template parameter,
and each constructor takes a Container reference argument.
This
container is copied into the Container member of each adaptor.
-1-
Any sequence supporting operations
front(),
back(),
push_back()
and
pop_front()
can be used to instantiate
queue.
In particular,
list
(lib.list)
and
deque
(lib.deque)
can be used.
-2- Returns:
x.c == y.c.
-3- Returns:
x.c < y.c.
-1-
Any sequence with random access iterator and supporting operations
front(),
push_back()
and
pop_back()
can be used to instantiate
priority_queue.
In particular,
vector
(lib.vector)
and
deque
(lib.deque)
can be used.
Instantiating
priority_queue
also involves supplying a function or function object for making priority comparisons;
the library assumes that the function or function object defines a strict
weak ordering (lib.alg.sorting).
-1- Requires:
x defines a strict weak ordering (lib.alg.sorting).
-2- Effects:
Initializes
comp with
x and
c with
y;
calls
make_heap(c.begin(), c.end(), comp).
-3- Requires:
x defines a strict weak ordering (lib.alg.sorting).
-4- Effects:
Initializes
c with
y and
comp with
x;
calls
c.insert(c.end(), first, last);
and finally calls
make_heap(c.begin(), c.end(), comp).
-1- Effects:
-2- Effects:
-1-
Any sequence supporting operations
back(),
push_back()
and
pop_back()
can be used to instantiate
stack.
In particular,
vector
(lib.vector),
list
(lib.list)
and
deque
(lib.deque)
can be used.
-1-
A
vector
is a kind of sequence that supports random access iterators.
In addition, it supports (amortized) constant time insert and erase operations at the end;
insert and erase in the middle take linear time.
Storage management is handled automatically, though hints can be given to improve efficiency.
-2-
A
vector
satisfies all of the requirements of a container and of a reversible container
(given in two tables in lib.container.requirements) and of a sequence,
including most of the optional sequence requirements (lib.sequence.reqmts).
The exceptions are the
push_front
and
pop_front
member functions, which are not provided.
Descriptions are provided here only for operations on
vector
that are not described in one of these tables
or for operations where there is additional semantic information.
-1- Complexity:
The constructor
template <class InputIterator> vector(InputIterator first, InputIterator last)
makes only
N
calls to the copy constructor of
T
(where
N
is the distance between
first
and
last)
and no reallocations if iterators first and last are of forward, bidirectional, or random access categories.
It does at most
2N
calls to the copy constructor of
T
and
logN
reallocations if they are just input iterators, since it is
impossible to determine the distance between
first
and
last
and then do copying.
-2- Effects:
-3- Effects:
-1- Returns:
The total number of elements that the vector can hold
without requiring reallocation.
-2- Effects:
A directive that informs a
vector
of a planned change in size, so that it can manage the storage allocation accordingly.
After
reserve(),
capacity()
is greater or equal to the argument of
reserve
if reallocation happens; and equal to the previous value of
capacity()
otherwise.
Reallocation happens at this point if and only if the current capacity is less than the
argument of
reserve().
-3- Complexity:
It does not change the size of the sequence and takes at most linear time in the size of the sequence.
-4- Throws:
length_error
if
n > max_size().*
-5- Notes:
Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence.
It is guaranteed that no reallocation takes place during insertions that happen after
a call to
reserve()
until the time when an insertion would make the size of the vector
greater than the size specified in the most recent call to
reserve().
-6- Effects:
-1- Notes:
Causes reallocation if the new size is greater than the old capacity.
If no reallocation happens, all the iterators and references before the insertion point remain valid.
If an exception is thrown other than by
the copy constructor or assignment operator of
T
there are no effects.
-2- Complexity:
If
first
and
last
are forward iterators, bidirectional iterators, or random access
iterators, the complexity is linear in the number of elements in the range
[first, last)
plus the distance to the end of the vector.
If they are input iterators, the complexity is proportional to
the number of elements in the range
[first, last)
times the distance to the end of the vector.
-3- Effects:
Invalidates all the iterators and references after the point of the erase.
-4- Complexity:
The destructor of
T
is called the number of times equal to the number of the elements erased,
but the assignment operator of
T
is called the number of times equal to the number of elements in the vector after the erased elements.
-5- Throws:
Nothing unless an exception is thrown by the
copy constructor or assignment operator of
T.
-1- Effects:
-1-
To optimize space allocation, a specialization of vector for
bool
elements is provided:
-2-
reference
is a class that simulates the behavior of references of a single bit in
vector<bool>.
-1-
Headers
<map>
and
<set>:
Header <map> synopsis
Header <set> synopsis
-1-
A
map
is a kind of associative container that supports unique keys (contains at most one of each key value) and
provides for fast retrieval of values of another type
T
based on the keys.
Map
supports bidirectional iterators.
-2-
A
map
satisfies all of the requirements of a container and of a reversible container
(lib.container.requirements) and of
an associative container (lib.associative.reqmts).
A
map
also provides most operations described in (lib.associative.reqmts)
for unique keys.
This means that a
map
supports the
a_uniq
operations in (lib.associative.reqmts)
but not the
a_eq
operations.
For a
map<Key,T>
the
key_type
is
Key
and the
value_type
is
pair<const Key,T>.
Descriptions are provided here only for operations on
map
that are not described in one of those tables
or for operations where there is additional semantic information.
-1- Effects:
Constructs an empty
map
using the specified comparison object and allocator.
-2- Complexity:
Constant.
-3- Effects:
Constructs an empty
map
using the specified comparison object and allocator,
and inserts elements from the range
[first, last).
-4- Complexity:
Linear in N if the range
[first, last)
is already sorted using comp
and otherwise N log N, where N
is last - first.
-1- Returns:
(*((insert(make_pair(x, T()))).first)).second.
-1-
The
find,
lower_bound,
upper_bound
and
equal_range
member functions each have two versions,
one const and the other non-const.
In each case the behavior of the two functions is identical
except that the const version returns a
const_iterator
and the non-const version an
iterator
(lib.associative.reqmts).
-1- Effects:
-1-
A
multimap
is a kind of associative container that supports equivalent keys (possibly containing multiple copies of
the same key value) and provides for fast retrieval of values of another type
T
based on the keys.
Multimap
supports bidirectional iterators.
-2-
A
multimap
satisfies all of the requirements of a container and of a reversible container
(lib.container.requirements) and of
an associative container (lib.associative.reqmts).
A
multimap
also provides most operations described in (lib.associative.reqmts)
for equal keys.
This means that a
multimap
supports the
a_eq
operations in
(lib.associative.reqmts)
but not the
a_uniq
operations.
For a
multimap<Key,T>
the
key_type
is
Key
and the
value_type
is
pair<const Key,T>.
Descriptions are provided here only for operations on
multimap
that are not described in one of those tables
or for operations where there is additional semantic information.
-1- Effects:
Constructs an empty
multimap
using the specified comparison object and allocator.
-2- Complexity:
Constant.
-3- Effects:
Constructs an empty
multimap
using the specified comparison object and allocator,
and inserts elements from the range
[first, last).
-4- Complexity:
Linear in N if the range
[first, last).
is already sorted using comp
and otherwise N log N,
where N is
last - first.
-1-
The
find,
lower_bound,
upper_bound,
and
equal_range
member functions each have two versions, one const and one non-const.
In each case the behavior of the two versions is identical
except that the const version returns a
const_iterator
and the non-const version an
iterator(_lib.associative.reqmts).
-1- Effects:
-1-
A
set
is a kind of associative container that supports unique keys (contains at most one of each key value) and
provides for fast retrieval of the keys themselves.
Set
supports bidirectional iterators.
-2-
A
set
satisfies all of the requirements of a container and of a reversible container
(lib.container.requirements), and of
an associative container (lib.associative.reqmts).
A
set
also provides most operations described in (lib.associative.reqmts)
for unique keys.
This means that a
set
supports the
a_uniq
operations in (lib.associative.reqmts)
but not the
a_eq
operations.
For a
set<Key>
both the
key_type
and
value_type
are
Key.
Descriptions are provided here only for operations on
set
that are not described in one of these tables
and for operations where there is additional semantic information.
-1- Effects:
Constructs an empty set using the specified comparison objects and allocator.
-2- Complexity:
Constant.
-3- Effects:
Constructs an empty
set
using the specified comparison object and allocator,
and inserts elements from the range
[first, last).
-4- Complexity:
Linear in N if the range
[first, last)
is already sorted using comp
and otherwise N log N,
where N is
last - first.
-1- Effects:
-1-
A
multiset
is a kind of associative container that supports equivalent keys (possibly contains multiple copies of
the same key value) and provides for fast retrieval of the keys themselves.
Multiset
supports bidirectional iterators.
-2-
A
multiset
satisfies all of the requirements of a container and of a reversible container
(lib.container.requirements), and of
an associative container (lib.associative.reqmts).
multiset
also provides most operations described in
(lib.associative.reqmts)
for duplicate keys.
This means that a
multiset
supports the
a_eq
operations in
(lib.associative.reqmts)
but not the
a_uniq
operations.
For a
multiset<Key>
both the
key_type
and
value_type
are
Key.
Descriptions are provided here only for operations on
multiset
that are not described in one of these tables
and for operations where there is additional semantic information.
-1- Effects:
Constructs an empty set using the specified comparison object and allocator.
-2- Complexity:
Constant.
-3- Effects:
Constructs an empty
multiset
using the specified comparison object and allocator,
and inserts elements from the range
[first, last).
-4- Complexity:
Linear in N
if the range
[first, last)
is already sorted using comp and otherwise N log N,
where N is
last - first.
-1- Effects:
Header <bitset> synopsis
-1-
The header
<bitset>
defines a template class and several related functions for representing
and manipulating fixed-size sequences of bits.
-2-
The template class
bitset<N>
describes an object that can store a sequence consisting of a fixed number of
bits, N .
-3-
Each bit represents either the value zero (reset) or one (set).
To
toggle
a bit is to change the value zero to one, or the value one to
zero.
Each bit has a non-negative position pos .
When converting
between an object of class
bitset<N>
and a value of some
integral type, bit position pos corresponds to the
bit value
1 << pos .
The integral value corresponding to two
or more bits is the sum of their bit values.
-4-
The functions described in this subclause can report three kinds of
errors, each associated with a distinct exception:
-1- Effects:
Constructs an object of class
bitset<N>,
initializing all bits to zero.
-2- Effects:
Constructs an object of class
bitset<N>,
initializing the first M bit positions to the corresponding bit
values in val .
M is the smaller of N and the value
CHAR_BIT * sizeof (unsigned long).*
-3- Requires:
pos <= str.size().
-4- Throws:
out_of_range
if
pos > str.size().
-5- Effects:
Determines the effective length
rlen of the initializing string as the smaller of
n and
str.size() - pos.
-6-
An element of the constructed string has value zero if the
corresponding character in str , beginning at position
pos , is
0.
Otherwise, the element has the value one.
Character position pos + M - 1 corresponds to bit position zero.
Subsequent decreasing character positions correspond to increasing bit positions.
-7-
If M < N , remaining bit positions are initialized to zero.
-1- Effects:
Clears each bit in
*this
for which the corresponding bit in rhs is clear, and leaves all other bits unchanged.
-2- Returns:
*this.
-3- Effects:
Sets each bit in
*this
for which the corresponding bit in rhs is set, and leaves all other bits unchanged.
-4- Returns:
*this.
-5- Effects:
Toggles each bit in
*this
for which the corresponding bit in rhs is set, and leaves all other bits unchanged.
-6- Returns:
*this.
-7- Effects:
Replaces each bit at position I in
*this
with a value determined as follows:
-8- Returns:
*this.
-9- Effects:
Replaces each bit at position I in
*this
with a value determined as follows:
-10- Returns:
*this.
-11- Effects:
Sets all bits in
*this.
-12- Returns:
*this.
-13- Requires:
pos is valid
-14- Throws:
out_of_range
if pos does not correspond to a valid bit position.
-15- Effects:
Stores a new value in the bit at position pos in
*this.
If val is nonzero, the stored value is one, otherwise it is zero.
-16- Returns:
*this.
-17- Effects:
Resets all bits in
*this.
-18- Returns:
*this.
-19- Requires:
pos is valid
-1- Returns:
bitset<N>( lhs ) &= rhs.
-2- Returns:
bitset<N>( lhs ) |= rhs.
-3- Returns:
bitset<N>( lhs ) ^= rhs.
-4-
A formatted input function (lib.istream.formatted).
-5- Effects:
Extracts up to N (single-byte) characters from is .
Stores these characters in a temporary object str of type
string,
then evaluates the expression
x = bitset<N>(str).
Characters are extracted and stored until any of the following occurs:
-6-
If no characters are stored in str , calls
is.setstate(ios::failbit)
(which may throw
ios_base::failure
(lib.iostate.flags).
-7- Returns:
is .
-8- Returns:
os << x.template to_string<charT,traits,allocator<charT> >()
(lib.ostream.formatted).
void merge(list<T,Allocator>& x );
template <class Compare> void merge(list<T,Allocator>& x , Compare comp );
void reverse();
void sort();
template <class Compare> void sort(Compare comp );
23.2.2.5 - list specialized algorithms [lib.list.special]
template <class T, class Allocator>
void swap(list<T,Allocator>& x, list<T,Allocator>& y);
x.swap(y);
23.2.3 - Container adaptors [lib.container.adaptors]
23.2.3.1 - Template class queue [lib.queue]
namespace std {
template <class T, class Container = deque<T> >
class queue {
public:
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef Container container_type;
protected:
Container c;
public:
explicit queue(const Container& = Container());
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
value_type& front() { return c.front(); }
const value_type& front() const { return c.front(); }
value_type& back() { return c.back(); }
const value_type& back() const { return c.back(); }
void push(const value_type& x) { c.push_back(x); }
void pop() { c.pop_front(); }
};
template <class T, class Container>
bool operator==(const queue<T, Container>& x,
const queue<T, Container>& y);
template <class T, class Container>
bool operator< (const queue<T, Container>& x,
const queue<T, Container>& y);
template <class T, class Container>
bool operator!=(const queue<T, Container>& x,
const queue<T, Container>& y);
template <class T, class Container>
bool operator> (const queue<T, Container>& x,
const queue<T, Container>& y);
template <class T, class Container>
bool operator>=(const queue<T, Container>& x,
const queue<T, Container>& y);
template <class T, class Container>
bool operator<=(const queue<T, Container>& x,
const queue<T, Container>& y);
}
operator==
operator<
23.2.3.2 - Template class priority_queue [lib.priority.queue]
namespace std {
template <class T, class Container = vector<T>,
class Compare = less<typename Container::value_type> >
class priority_queue {
public:
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef Container container_type;
protected:
Container c;
Compare comp;
public:
explicit priority_queue(const Compare& x = Compare(),
const Container& = Container());
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& x = Compare(),
const Container& = Container());
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
const value_type& top() const { return c.front(); }
void push(const value_type& x);
void pop();
};
//
no equality is provided
}
23.2.3.2.1 - priority_queue constructors [lib.priqueue.cons]
priority_queue(const Compare& x = Compare(),
const Container& y = Container());
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& x = Compare(),
const Container& y = Container());
23.2.3.2.2 - priority_queue members [lib.priqueue.members]
void push(const value_type& x);
c.push_back(x);
push_heap(c.begin(), c.end(), comp);
void pop();
pop_heap(c.begin(), c.end(), comp);
c.pop_back();
23.2.3.3 - Template class stack [lib.stack]
namespace std {
template <class T, class Container = deque<T> >
class stack {
public:
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef Container container_type;
protected:
Container c;
public:
explicit stack(const Container& = Container());
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
value_type& top() { return c.back(); }
const value_type& top() const { return c.back(); }
void push(const value_type& x) { c.push_back(x); }
void pop() { c.pop_back(); }
};
template <class T, class Container>
bool operator==(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator< (const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator!=(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator> (const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator>=(const stack<T, Container>& x,
const stack<T, Container>& y);
template <class T, class Container>
bool operator<=(const stack<T, Container>& x,
const stack<T, Container>& y);
}
23.2.4 - Template class vector [lib.vector]
namespace std {
template <class T, class Allocator = allocator<T> >
class vector {
public:
//
types:
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef T value_type;
typedef Allocator allocator_type;
typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer const_pointer
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//
lib.vector.cons construct/copy/destroy:
explicit vector(const Allocator& = Allocator());
explicit vector(size_type n, const T& value = T(),
const Allocator& = Allocator());
template <class InputIterator>
vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
vector(const vector<T,Allocator>& x);
~vector();
vector<T,Allocator>& operator=(const vector<T,Allocator>& x);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
void assign(size_type n, const T& u);
allocator_type get_allocator() const;
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
lib.vector.capacity capacity:
size_type size() const;
size_type max_size() const;
void resize(size_type sz, T c = T());
size_type capacity() const;
bool empty() const;
void reserve(size_type n);
//
element access:
reference operator[](size_type n);
const_reference operator[](size_type n) const;
const_reference at(size_type n) const;
reference at(size_type n);
reference front();
const_reference front() const;
reference back();
const_reference back() const;
//
lib.vector.modifiers modifiers:
void push_back(const T& x);
void pop_back();
iterator insert(iterator position, const T& x);
void insert(iterator position, size_type n, const T& x);
template <class InputIterator>
void insert(iterator position,
InputIterator first, InputIterator last);
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
void swap(vector<T,Allocator>&);
void clear();
};
template <class T, class Allocator>
bool operator==(const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
template <class T, class Allocator>
bool operator< (const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
template <class T, class Allocator>
bool operator!=(const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
template <class T, class Allocator>
bool operator> (const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
template <class T, class Allocator>
bool operator>=(const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
template <class T, class Allocator>
bool operator<=(const vector<T,Allocator>& x,
const vector<T,Allocator>& y);
//
specialized algorithms:
template <class T, class Allocator>
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);
}
23.2.4.1 - vector constructors, copy, and assignment [lib.vector.cons]
vector(const Allocator& = Allocator());
explicit vector(size_type n, const T& value = T(),
const Allocator& = Allocator());
template <class InputIterator>
vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
vector(const vector<T,Allocator>& x);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
erase(begin(), end());
insert(begin(), first, last);
void assign(size_type n, const T& t);
erase(begin(), end());
insert(begin(), n, t);
23.2.4.2 - vector capacity [lib.vector.capacity]
size_type capacity() const;
void reserve(size_type n);
[Footnote:
reserve()
uses
Allocator::allocate()
which may throw an appropriate exception.
--- end foonote]
void resize(size_type sz, T c = T());
if (sz > size())
insert(end(), sz-size(), c);
else if (sz < size())
erase(begin()+sz, end());
else
; //
do nothing
23.2.4.3 - vector modifiers [lib.vector.modifiers]
iterator insert(iterator position, const T& x);
void insert(iterator position, size_type n, const T& x);
template <class InputIterator>
void insert(iterator position, InputIterator first, InputIterator last);
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
23.2.4.4 - vector specialized algorithms [lib.vector.special]
template <class T, class Allocator>
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y);
x.swap(y);
23.2.5 - Class vector<bool> [lib.vector.bool]
namespace std {
template <class Allocator> class vector<bool, Allocator> {
public:
//
types:
typedef bool const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef bool value_type;
typedef Allocator allocator_type;
typedef implementation defined pointer;
typedef implementation defined const_pointer
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//
bit reference:
class reference {
friend class vector;
reference();
public:
~reference();
operator bool() const;
reference& operator=(const bool x);
reference& operator=(const reference& x);
void flip(); // flips the bit
};
//
construct/copy/destroy:
explicit vector(const Allocator& = Allocator());
explicit vector(size_type n, const bool& value = bool(),
const Allocator& = Allocator());
template <class InputIterator>
vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
vector(const vector<bool,Allocator>& x);
~vector();
vector<bool,Allocator>& operator=(const vector<bool,Allocator>& x);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
void assign(size_type n, const T& t);
allocator_type get_allocator() const;
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
capacity:
size_type size() const;
size_type max_size() const;
void resize(size_type sz, bool c = false);
size_type capacity() const;
bool empty() const;
void reserve(size_type n);
//
element access:
reference operator[](size_type n);
const_reference operator[](size_type n) const;
const_reference at(size_type n) const;
reference at(size_type n);
reference front();
const_reference front() const;
reference back();
const_reference back() const;
//
modifiers:
void push_back(const bool& x);
void pop_back();
iterator insert(iterator position, const bool& x);
void insert (iterator position, size_type n, const bool& x);
template <class InputIterator>
void insert(iterator position,
InputIterator first, InputIterator last);
iterator erase(iterator position);
iterator erase(iterator first, iterator last);
void swap(vector<bool,Allocator>&);
static void swap(reference x, reference y);
void flip(); //
flips all bits
void clear();
};
template <class Allocator>
bool operator==(const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
template <class Allocator>
bool operator< (const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
template <class Allocator>
bool operator!=(const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
template <class Allocator>
bool operator> (const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
template <class Allocator>
bool operator>=(const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
template <class Allocator>
bool operator<=(const vector<bool,Allocator>& x,
const vector<bool,Allocator>& y);
//
specialized algorithms:
template <class Allocator>
void swap(vector<bool,Allocator>& x, vector<bool,Allocator>& y);
}
23.3 - Associative containers [lib.associative]
namespace std {
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T> > >
class map;
template <class Key, class T, class Compare, class Allocator>
bool operator==(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator< (const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator!=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator> (const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator>=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator<=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
void swap(map<Key,T,Compare,Allocator>& x,
map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T> > >
class multimap;
template <class Key, class T, class Compare, class Allocator>
bool operator==(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator< (const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator!=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator> (const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator>=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator<=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
void swap(multimap<Key,T,Compare,Allocator>& x,
multimap<Key,T,Compare,Allocator>& y);
}
namespace std {
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key> >
class set;
template <class Key, class Compare, class Allocator>
bool operator==(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator< (const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator!=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator> (const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator>=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator<=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
void swap(set<Key,Compare,Allocator>& x,
set<Key,Compare,Allocator>& y);
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key> >
class multiset;
template <class Key, class Compare, class Allocator>
bool operator==(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator< (const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator!=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator> (const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator>=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator<=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
void swap(multiset<Key,Compare,Allocator>& x,
multiset<Key,Compare,Allocator>& y);
}
23.3.1 - Template class map [lib.map]
namespace std {
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T> > >
class map {
public:
//
types:
typedef Key key_type;
typedef T mapped_type;
typedef pair<const Key, T> value_type;
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
class value_compare
: public binary_function<value_type,value_type,bool> {
friend class map;
protected:
Compare comp;
value_compare(Compare c) : comp(c) {}
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x.first, y.first);
}
};
//
lib.map.cons construct/copy/destroy:
explicit map(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
map(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
map(const map<Key,T,Compare,Allocator>& x);
~map();
map<Key,T,Compare,Allocator>&
operator=(const map<Key,T,Compare,Allocator>& x);
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
capacity:
bool empty() const;
size_type size() const;
size_type max_size() const;
//
lib.map.access element access:
T& operator[](const key_type& x);
//
modifiers:
pair<iterator, bool> insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
void swap(map<Key,T,Compare,Allocator>&);
void clear();
//
observers:
key_compare key_comp() const;
value_compare value_comp() const;
//
lib.map.ops map operations:
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator>
equal_range(const key_type& x);
pair<const_iterator,const_iterator>
equal_range(const key_type& x) const;
};
template <class Key, class T, class Compare, class Allocator>
bool operator==(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator< (const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator!=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator> (const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator>=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator<=(const map<Key,T,Compare,Allocator>& x,
const map<Key,T,Compare,Allocator>& y);
//
specialized algorithms:
template <class Key, class T, class Compare, class Allocator>
void swap(map<Key,T,Compare,Allocator>& x,
map<Key,T,Compare,Allocator>& y);
}
23.3.1.1 - map constructors, copy, and assignment [lib.map.cons]
explicit map(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
map(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
23.3.1.2 - map element access [lib.map.access]
T& operator[](const key_type& x);
23.3.1.3 - map operations [lib.map.ops]
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type &x) const;
pair<iterator, iterator>
equal_range(const_key_type &x);
pair<const_iterator, const_iterator>
equal_range(const key_type& x) const;
23.3.1.4 - map specialized algorithms [lib.map.special]
template <class Key, class T, class Compare, class Allocator>
void swap(map<Key,T,Compare,Allocator>& x,
map<Key,T,Compare,Allocator>& y);
x.swap(y);
23.3.2 - Template class multimap [lib.multimap]
namespace std {
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T> > >
class multimap {
public:
//
types:
typedef Key key_type;
typedef T mapped_type;
typedef pair<const Key,T> value_type;
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
class value_compare
: public binary_function<value_type,value_type,bool> {
friend class multimap;
protected:
Compare comp;
value_compare(Compare c) : comp(c) {}
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x.first, y.first);
}
};
//
construct/copy/destroy:
explicit multimap(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
multimap(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Allocator& = Allocator());
multimap(const multimap<Key,T,Compare,Allocator>& x);
~multimap();
multimap<Key,T,Compare,Allocator>&
operator=(const multimap<Key,T,Compare,Allocator>& x);
allocator_type get_allocator() const;
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
capacity:
bool empty() const;
size_type size() const;
size_type max_size() const;
//
modifiers:
iterator insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
void swap(multimap<Key,T,Compare,Allocator>&);
void clear();
//
observers:
key_compare key_comp() const;
value_compare value_comp() const;
//
map operations:
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator>
equal_range(const key_type& x);
pair<const_iterator,const_iterator>
equal_range(const key_type& x) const;
};
template <class Key, class T, class Compare, class Allocator>
bool operator==(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator< (const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator!=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator> (const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator>=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool operator<=(const multimap<Key,T,Compare,Allocator>& x,
const multimap<Key,T,Compare,Allocator>& y);
//
specialized algorithms:
template <class Key, class T, class Compare, class Allocator>
void swap(multimap<Key,T,Compare,Allocator>& x,
multimap<Key,T,Compare,Allocator>& y);
}
23.3.2.1 - multimap constructors [lib.multimap.cons]
explicit multimap(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
multimap(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Allocator& = Allocator()0;
23.3.2.2 - multimap operations [lib.multimap.ops]
iterator find(const key_type &x);
const_iterator find(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
pair<iterator, iterator>
equal_range(const key_type& x);
pair<const_iterator, const_iterator>
equal_range(const_key_type& x) const;
23.3.2.3 - multimap specialized algorithms [lib.multimap.special]
template <class Key, class T, class Compare, class Allocator>
void swap(multimap<Key,T,Compare,Allocator>& x,
multimap<Key,T,Compare,Allocator>& y);
x.swap(y);
23.3.3 - Template class set [lib.set]
namespace std {
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key> >
class set {
public:
//
types:
typedef Key key_type;
typedef Key value_type;
typedef Compare key_compare;
typedef Compare value_compare;
typedef Allocator allocator_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//
lib.set.cons construct/copy/destroy:
explicit set(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
set(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
set(const set<Key,Compare,Allocator>& x);
~set();
set<Key,Compare,Allocator>& operator=
(const set<Key,Compare,Allocator>& x);
allocator_type get_allocator() const;
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
capacity:
bool empty() const;
size_type size() const;
size_type max_size() const;
//
modifiers:
pair<iterator,bool> insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
void swap(set<Key,Compare,Allocator>&);
void clear();
//
observers:
key_compare key_comp() const;
value_compare value_comp() const;
//
set operations:
iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x) const;
};
template <class Key, class Compare, class Allocator>
bool operator==(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator< (const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator!=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator> (const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator>=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator<=(const set<Key,Compare,Allocator>& x,
const set<Key,Compare,Allocator>& y);
//
specialized algorithms:
template <class Key, class Compare, class Allocator>
void swap(set<Key,Compare,Allocator>& x,
set<Key,Compare,Allocator>& y);
}
23.3.3.1 - set constructors, copy, and assignment [lib.set.cons]
explicit set(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
set(InputIterator first, last,
const Compare& comp = Compare(), const Allocator& = Allocator());
23.3.3.2 - set specialized algorithms [lib.set.special]
template <class Key, class Compare, class Allocator>
void swap(set<Key,Compare,Allocator>& x,
set<Key,Compare,Allocator>& y);
x.swap(y);
23.3.4 - Template class multiset [lib.multiset]
namespace std {
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key> >
class multiset {
public:
//
types:
typedef Key key_type;
typedef Key value_type;
typedef Compare key_compare;
typedef Compare value_compare;
typedef Allocator allocator_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::const_reference const_reference;
typedef implementation defined iterator; // See lib.container.requirements
typedef implementation defined const_iterator; // See lib.container.requirements
typedef implementation defined size_type; // See lib.container.requirements
typedef implementation defined difference_type;// See lib.container.requirements
typedef typename Allocator::pointer pointer;
typedef typename Allocator::const_pointer const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
//
construct/copy/destroy:
explicit multiset(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
multiset(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const Allocator& = Allocator());
multiset(const multiset<Key,Compare,Allocator>& x);
~multiset();
multiset<Key,Compare,Allocator>&
operator=(const multiset<Key,Compare,Allocator>& x);
allocator_type get_allocator() const;
//
iterators:
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
//
capacity:
bool empty() const;
size_type size() const;
size_type max_size() const;
//
modifiers:
iterator insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
void swap(multiset<Key,Compare,Allocator>&);
void clear();
//
observers:
key_compare key_comp() const;
value_compare value_comp() const;
//
set operations:
iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x) const;
};
template <class Key, class Compare, class Allocator>
bool operator==(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator< (const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator!=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator> (const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator>=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
template <class Key, class Compare, class Allocator>
bool operator<=(const multiset<Key,Compare,Allocator>& x,
const multiset<Key,Compare,Allocator>& y);
//
specialized algorithms:
template <class Key, class Compare, class Allocator>
void swap(multiset<Key,Compare,Allocator>& x,
multiset<Key,Compare,Allocator>& y);
}
23.3.4.1 - multiset constructors [lib.multiset.cons]
explicit multiset(const Compare& comp = Compare(),
const Allocator& = Allocator());
template <class InputIterator>
multiset(InputIterator first, last,
const Compare& comp = Compare(), const Allocator& = Allocator());
23.3.4.2 - multiset specialized algorithms [lib.multiset.special]
template <class Key, class Compare, class Allocator>
void swap(multiset<Key,Compare,Allocator>& x,
multiset<Key,Compare,Allocator>& y);
x.swap(y);
23.3.5 - Template class bitset [lib.template.bitset]
#include <cstddef> //
for size_t
#include <string>
#include <stdexcept> // for invalid_argument,
// out_of_range, overflow_error
#include <iosfwd> // for istream, ostream
namespace std {
template <size_t N> class bitset;
//
lib.bitset.operators bitset operations:
template <size_t N>
bitset<N> operator&(const bitset<N>&, const bitset<N>&);
template <size_t N>
bitset<N> operator|(const bitset<N>&, const bitset<N>&);
template <size_t N>
bitset<N> operator^(const bitset<N>&, const bitset<N>&);
template <class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is , bitset<N>& x );
template <class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os , const bitset<N>& x );
}
namespace std {
template<size_t N> class bitset {
public:
//
bit reference:
class reference {
friend class bitset;
reference();
public:
~reference();
reference& operator=(bool x); // for b[i] = x;
reference& operator=(const reference&); // for b[i] = b[j];
bool operator~() const; // flips the bit
operator bool() const; // for x = b[i];
reference& flip(); // for b[i].flip();
};
//
lib.bitset.cons constructors:
bitset();
bitset(unsigned long val );
template<class charT, class traits, class Allocator>
explicit bitset(
const basic_string<charT,traits,Allocator>& str ,
typename basic_string<charT,traits,Allocator>::size_type pos = 0,
typename basic_string<charT,traits,Allocator>::size_type n =
basic_string<charT,traits,Allocator>::npos);
//
lib.bitset.members bitset operations:
bitset<N>& operator&=(const bitset<N>& rhs );
bitset<N>& operator|=(const bitset<N>& rhs );
bitset<N>& operator^=(const bitset<N>& rhs );
bitset<N>& operator<<=(size_t pos );
bitset<N>& operator>>=(size_t pos );
bitset<N>& set();
bitset<N>& set(size_t pos , int val = true);
bitset<N>& reset();
bitset<N>& reset(size_t pos );
bitset<N> operator~() const;
bitset<N>& flip();
bitset<N>& flip(size_t pos );
//
element access:
reference operator[](size_t pos ); // for b[i];
unsigned long to_ulong() const;
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator> to_string() const;
size_t count() const;
size_t size() const;
bool operator==(const bitset<N>& rhs ) const;
bool operator!=(const bitset<N>& rhs ) const;
bool test(size_t pos ) const;
bool any() const;
bool none() const;
bitset<N> operator<<(size_t pos ) const;
bitset<N> operator>>(size_t pos ) const;
};
}
23.3.5.1 - bitset constructors [lib.bitset.cons]
bitset();
bitset(unsigned long val );
[Footnote:
The macro
CHAR_BIT
is defined in
<climits>
(lib.support.limits).
--- end foonote]
If M < N , remaining bit positions are initialized to zero.
template <class charT, class traits, class Allocator>
explicit
bitset(const basic_string<charT, traits, Allocator>& str,
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
typename basic_string<charT, traits, Allocator>::size_type n =
basic_string<charT, traits, Allocator>::npos);
The function then throws
invalid_argument
if any of the rlen
characters in str beginning at position pos is
other than
0
or
1.
Otherwise, the function constructs an object of class
bitset<N>,
initializing the first M bit
positions to values determined from the corresponding characters in the string
str .
M is the smaller of N and rlen .
23.3.5.2 - bitset members [lib.bitset.members]
bitset<N>& operator&=(const bitset<N>& rhs );
bitset<N>& operator|=(const bitset<N>& rhs );
bitset<N>& operator^=(const bitset<N>& rhs );
bitset<N>& operator<<=(size_t pos );
bitset<N>& operator>>=(size_t pos );
bitset<N>& set();
bitset<N>& set(size_t pos , int val = 1);
bitset<N>& reset();
bitset<N>& reset(size_t pos );
bitset<N> operator~() const;
bitset<N>& flip();
bitset<N>& flip(size_t pos );
unsigned long to_ulong() const;
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator> to_string() const;
size_t count() const;
size_t size() const;
bool operator==(const bitset<N>& rhs ) const;
bool operator!=(const bitset<N>& rhs ) const;
bool test(size_t pos ) const;
bool any() const;
bool none() const;
bitset<N> operator<<(size_t pos ) const;
bitset<N> operator>>(size_t pos ) const;
23.3.5.3 - bitset operators [lib.bitset.operators]
bitset<N> operator&(const bitset<N>& lhs , const bitset<N>& rhs );
bitset<N> operator|(const bitset<N>& lhs , const bitset<N>& rhs );
bitset<N> operator^(const bitset<N>& lhs , const bitset<N>& rhs );
template <class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is , bitset<N>& x );
template <class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os , const bitset<N>& x );