An AssociativeContainer is an ordered Container that provides fast lookup of objects based on keys.
An associative container supports unique keys if it may contain at most one element for each key. Otherwise, it supports equivalent keys.
LegendX
An associative container class T
The element type of X
A
The allocator type of X
: X::allocator_type
if it exists, otherwise std::allocator<X::value_type> a A value of type X
a2 A value of a type Y
whose node handles are compatible with X
b A value of type X
or const X u A name of a variable beging declared a_uniq A value of type X
when X
supports unique keys a_eq A value of type X
when X
supports equivalent keys a_tran A value of type X
or const X when type X::key_compare::is_transparent
exists i, j The LegacyInputIterators referring to elements implicitly convertible to X::value_type
[
i,
j)
A valid range rg
R
that models container-compatible-range<value_type>
p A valid constant iterator to a q A valid dereferenceable constant iterator to a r A valid dereferenceable iterator to a q1, q2 A valid range of const iterators in a il An object of type std::initializer_list<X::value_type> t A value of type X::value_type
k A value of type X::key_type
c A value of type X::key_compare
or const X::key_compare kl A value such that a is partitioned with respect to c(x, kl), with x the key value of e and e in a ku A value such that a is partitioned with respect to !c(ku, x), with x the key value of e and e in a ke A value such that a is partitioned with respect to c(x, ke) and !c(ke, x), with c(x, ke) implying !c(ke, x) and with x the key value of e and e in a kx
X::iterator
or X::const_iterator
A
nh A non-const rvalue of type X::node_type
Expression Result Preconditions Effects Returns Complexity X(c) Constructs an empty container. Uses a copy of c as a comparison object Constant X u = X();
key_compare
meets the DefaultConstructible requirements Constructs an empty container. Uses Compare() as a comparison object Constant X(i, j, c) value_type
is EmplaceConstructible into X
from *i Constructs an empty container and inserts elements from the range [
i,
j)
into it; uses c as a comparison object N·log(N) in general, where N
has the value std::distance(i, j); linear if [
i,
j)
is sorted with respect to value_comp() X(i, j) key_compare
meets the DefaultConstructible requirements. value_type
is EmplaceConstructible into X
from *i Constructs an empty container and inserts elements from the range [
i,
j)
into it; uses Compare() as a comparison object X(from_range, rg, c)
value_type
is EmplaceConstructible into X
from *ranges::begin(rg) Constructs an empty container and inserts each element from rg into it. Uses c as the comparison object N·log(N) in general, where N
has the value ranges::distance(rg); linear if rg is sorted with respect to value_comp() X(from_range, rg)
key_compare
meets the DefaultConstructible requirements. value_type
is EmplaceConstructible into X
from *ranges::begin(rg) Constructs an empty container and inserts each element from rg into it. Uses Compare() as the comparison object X(il, c) X(il.begin(), il.end(), c) X(il) X(il.begin(), il.end()) a = il X& value_type
is CopyInsertable into X
and CopyAssignable Assigns the range [
il.begin(),
il.end())
into a. All existing elements of a are either assigned to or destroyed N·log(N) in general, where N
has the value il.size() + a.size(); linear if [
il.begin(),
il.end())
is sorted with respect to value_comp() b.key_comp() X::key_compare
The comparison object out of which b was constructed Constant b.value_comp() X::value_compare
An object of value_compare
constructed out of the comparison object Constant a_uniq.emplace(args) std::pair<value_type
is EmplaceConstructible into X
from args Inserts a value_type
object t constructed with std::forward<Args>(args)... 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 is true if and only if 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.emplace(args) iterator
value_type
is EmplaceConstructible into X
from args Inserts a value_type
object t constructed with std::forward<Args>(args).... If a range containing elements equivalent to t exists in a_eq, t is inserted at the end of that range An iterator pointing to the newly inserted element Logarithmic a.emplace_hint(p, args) iterator
Equivalent to
a.emplace(
std::forward<Args>(args)...), except that the element is inserted as close as possible to the position just prior to p
value_type
is MoveInsertable into X
; otherwise, value_type
is CopyInsertable into X
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 is true if and only if 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
If t is a non-const rvalue, value_type
is MoveInsertable into X
; otherwise, value_type
is CopyInsertable into X
Inserts t and returns the iterator pointing to the newly inserted element. If a range containing elements equivalent to t exists in a_eq, t is inserted at the end of that range Logarithmic a.insert(p, t) iterator
If t is a non-const rvalue, value_type
is MoveInsertable into X
; otherwise, value_type
is CopyInsertable into X
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. t is inserted as close as possible to the position just prior to p An iterator pointing to the element with key equivalent to the key of t Logarithmic in general, but amortized constant if t is inserted right before p a.insert(i, j) void value_type
is EmplaceConstructible into X
from *i. Neither i nor j are 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 N·log(a.size() + N), where N
has the value std::distance(i, j) a.insert_range(rg)
value_type
is EmplaceConstructible into X
from *ranges::begin(rg). rg and a do not overlap Inserts each element from rg 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 N·log(a.size() + N), where N
has the value ranges::distance(rg) a.insert(il) a.insert(il.begin(), il.end()) a_uniq.insert(nh) insert_return_type
nh is empty or
a_uniq.get_allocator()
==
nh.get_allocator() is true
inserted
is false, position
is end(), and node
is empty. Otherwise if the insertion took place, inserted
is true, position
points to the inserted element, and node
is empty; if the insertion failed, inserted
is false, node
has the previous value of nh, and position
points to an element with a key equivalent to nh.key() Logarithmic a_eq.insert(nh) iterator
nh is empty or
a_eq.get_allocator()
==
nh.get_allocator() is true
iterator
nh is empty or
a.get_allocator()
==
nh.get_allocator() is true
node_type
Removes the first element in the container with key equivalent to k A node_type
owning the element if found, otherwise an empty node_type
log(a.size()) a_tran.extract(kx)
node_type
Removes the first element in the container with key r such that !c(r, kx) && !c(kx, r) is true A node_type
owning the element if found, otherwise an empty node_type
log(a_tran.size()) a.extract(q) node_type
Removes the element pointed to by q A node_type
owning that element Amortized constant a.merge(a2) void a.get_allocator()N
has the value a2.size() a.erase(k) size_type
Erases all elements in the container with key equivalent to k The number of erased elements log(a.size())size_type
Erases all elements in the container with key r such that !c(r, kx) && !c(kx, r) is true The number of erased elements log(a_tran.size())iterator
Erases the element pointed to by q An iterator pointing to the element immediately following q prior to the element being erased. If no such element exists, returns a.end() Amortized constant a.erase(r) iterator
Erases the element pointed to by r An iterator pointing to the element immediately following r prior to the element being erased. If no such element exists, returns a.end() Amortized constant a.erase(q1, q2) iterator
Erases all the elements in the range
[
q1,
q2)
An iterator pointing to the element pointed to by q2 prior to any elements being erased. If no such element exists, a.end() is returned log(a.size()) + N, where N
has the value std::distance(q1, q2) a.clear() a.erase(a.begin(), a.end()). Ensures: a.empty() is true Linear in a.size() b.find(k) iterator
; const_iterator
for constant b An iterator pointing to an element with the key equivalent to k, or b.end() if such an element is not found Logarithmic a_tran.find(ke) iterator
; const_iterator
for constant a_tran An iterator pointing to an element with key r such that
!c(r, ke) &&
!c(ke, r) is true, or a_tran.end() if such an element is not found
size_type
The number of elements with key equivalent to k log(b.size())size_type
The number of elements with key r such that
!c(r, ke) &&
!c(ke, r)
return
a_tran.find(ke) !=
a_tran.end();
iterator
; const_iterator
for constant b An iterator pointing to the first element with key not less than k, or b.end() if such an element is not found Logarithmic a_tran.lower_bound(kl) iterator
; const_iterator
for constant a_tran An iterator pointing to the first element with key r such that !c(r, kl), or a_tran.end() if such an element is not found Logarithmic b.upper_bound(k) iterator
; const_iterator
for constant b An iterator pointing to the first element with key greater than k, or b.end() if such an element is not found Logarithmic a_tran.upper_bound(ku) iterator
; const_iterator
for constant a_tran An iterator pointing to the first element with key r such that c(ku, r), or a_tran.end() if such an element is not found Logarithmic b.equal_range(k) std::pair<std::pair<
const_iterator,
const_iterator> for constant b
return
std::make_pair(
b.lower_bound(k),
b.upper_bound(k));
std::pair<
const_iterator,
const_iterator> for constant a_tran
return
std::make_pair(
a_tran.lower_bound(ke),
a_tran.upper_bound(ke));
For associative containers where value_type
is the same as key_type
, both iterator
and const_iterator
are constant iterators. It is unspecified whether or not iterator
and const_iterator
are the same type.
Iterators of associative containers iterate through the containers in the non-descending order of keys where non-descending is defined by the comparison that was used to construct the containers. That is, given
If the distance from i to j is positive, then a.value_comp()(*j, *i) == false. Additionally, if a is an associative container with unique keys, the stronger condition a.value_comp()(*i, *j) != false holds.
The following standard library containers satisfy the AssociativeContainer requirements:
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4