Difference between revisions of "cpp/container/flat multiset"
m (+page, early draft.) |
m (→Member objects: fmt.) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title|flat_multiset}} | {{cpp/title|flat_multiset}} | ||
{{cpp/container/flat_multiset/navbar}} | {{cpp/container/flat_multiset/navbar}} | ||
− | {{ddcl|header= | + | {{ddcl|header=flat_set|since=c++23|1= |
template< | template< | ||
class Key, | class Key, | ||
Line 10: | Line 10: | ||
The flat multiset is a [[cpp/container#Container adaptors|container adaptor]] that gives the functionality of an associative container that stores a sorted set of objects of type {{tt|Key}}. Unlike {{lc|std::flat_set}}, multiple keys with equivalent values are allowed. Sorting is done using the key comparison function {{tt|Compare}}. | The flat multiset is a [[cpp/container#Container adaptors|container adaptor]] that gives the functionality of an associative container that stores a sorted set of objects of type {{tt|Key}}. Unlike {{lc|std::flat_set}}, multiple keys with equivalent values are allowed. Sorting is done using the key comparison function {{tt|Compare}}. | ||
+ | |||
+ | The class template {{tt|flat_multiset}} acts as a wrapper to the underlying sorted container passed as object of type {{tt|KeyContainer}}. | ||
Everywhere the standard library uses the {{named req|Compare}} requirements, uniqueness is determined by using the equivalence relation. Informally, two objects {{c|a}} and {{c|b}} are considered equivalent if neither compares less than the other: {{c|!comp(a, b) && !comp(b, a)}}. | Everywhere the standard library uses the {{named req|Compare}} requirements, uniqueness is determined by using the equivalence relation. Informally, two objects {{c|a}} and {{c|b}} are considered equivalent if neither compares less than the other: {{c|!comp(a, b) && !comp(b, a)}}. | ||
− | + | <!--For std::multimap the following is true (what about flat_multiset?): The order of the key pairs whose keys compare equivalent is the order of insertion and does not change.--> | |
− | {{tt|std::flat_multiset}} meets the requirements of {{named req|Container}}, {{named req|ReversibleContainer}}, | + | {{tt|std::flat_multiset}} meets the requirements of {{named req|Container}}, {{named req|ReversibleContainer}}, {{lsd|cpp/named_req/Container#Optional container requirements}}, and all requirements of {{named req|AssociativeContainer}} (including logarithmic search complexity), except that: |
* requirements related to nodes are not applicable, | * requirements related to nodes are not applicable, | ||
* iterator invalidation requirements differ, <!--TODO: describe iterator/pointer invalidation properties, maybe per each function --> | * iterator invalidation requirements differ, <!--TODO: describe iterator/pointer invalidation properties, maybe per each function --> | ||
Line 27: | Line 29: | ||
===Template parameters=== | ===Template parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par|Key|The type of the stored elements. The | + | {{par|Key|The type of the stored elements. The program is ill-formed if {{tt|Key}} is not the same type as {{tt|KeyContainer::value_type}}.}} |
{{par|Compare|A {{named req|Compare}} type providing a strict weak ordering. | {{par|Compare|A {{named req|Compare}} type providing a strict weak ordering. | ||
{{par|KeyContainer|The type of the underlying {{named req|SequenceContainer}} to store the elements. The iterators of such container should satisfy {{named req|RandomAccessIterator}} or model {{lconcept|random_access_iterator}}. | {{par|KeyContainer|The type of the underlying {{named req|SequenceContainer}} to store the elements. The iterators of such container should satisfy {{named req|RandomAccessIterator}} or model {{lconcept|random_access_iterator}}. | ||
Line 35: | Line 37: | ||
===Member types=== | ===Member types=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc hitem| | + | {{dsc hitem|Type|Definition}} |
{{dsc inc|cpp/container/dsc container_type|flat_multiset}} | {{dsc inc|cpp/container/dsc container_type|flat_multiset}} | ||
{{dsc inc|cpp/container/dsc key_type|flat_multiset}} | {{dsc inc|cpp/container/dsc key_type|flat_multiset}} | ||
Line 53: | Line 55: | ||
===Member objects=== | ===Member objects=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc hitem|Member | + | {{dsc hitem|Member|Description}} |
− | {{dsc expos mem obj|private=yes| | + | {{dsc expos mem obj|c|id=c|private=yes|spec={{tt|container_type}}|the adapted container}} |
− | {{dsc expos mem obj|private=yes| | + | {{dsc expos mem obj|compare|id=compare|private=yes|spec={{tt|key_compare}}|the comparison function object}} |
{{dsc end}} | {{dsc end}} | ||
Line 61: | Line 63: | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc|cpp/container/dsc constructor|flat_multiset}} | {{dsc inc|cpp/container/dsc constructor|flat_multiset}} | ||
− | {{dsc | + | {{dsc mem dtor|nolink=true|notes={{mark implicit}}|destroys every element of the container adaptor}} |
{{dsc inc|cpp/container/dsc operator{{=}}|flat_multiset}} | {{dsc inc|cpp/container/dsc operator{{=}}|flat_multiset}} | ||
Line 113: | Line 115: | ||
===Tags=== | ===Tags=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | |||
{{dsc inc|cpp/container/dsc sorted_equivalent}} | {{dsc inc|cpp/container/dsc sorted_equivalent}} | ||
{{dsc end}} | {{dsc end}} | ||
Line 146: | Line 147: | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc|cpp/container/dsc flat_set}} | {{dsc inc|cpp/container/dsc flat_set}} | ||
− | {{dsc inc|cpp/container/dsc | + | {{dsc inc|cpp/container/dsc multiset}} |
− | {{dsc inc|cpp/container/dsc | + | {{dsc inc|cpp/container/dsc unordered_multiset}} |
− | + | ||
{{dsc end}} | {{dsc end}} | ||
{{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|zh}} | {{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|zh}} | ||
− | <!--TODO: N4950::24.6. | + | <!--TODO: N4950::24.6.12 says: |
TODO: add this to the "Exceptions" sections of appropriate member functions: | TODO: add this to the "Exceptions" sections of appropriate member functions: | ||
6. If any member function in 24.6.12.2 exits via an exception, the invariant is restored. | 6. If any member function in 24.6.12.2 exits via an exception, the invariant is restored. |
Latest revision as of 14:53, 1 November 2024
Defined in header <flat_set>
|
||
template< class Key, |
(since C++23) | |
The flat multiset is a container adaptor that gives the functionality of an associative container that stores a sorted set of objects of type Key
. Unlike std::flat_set, multiple keys with equivalent values are allowed. Sorting is done using the key comparison function Compare
.
The class template flat_multiset
acts as a wrapper to the underlying sorted container passed as object of type KeyContainer
.
Everywhere the standard library uses the Compare requirements, uniqueness is determined by using the equivalence relation. Informally, two objects a and b are considered equivalent if neither compares less than the other: !comp(a, b) && !comp(b, a).
std::flat_multiset
meets the requirements of Container, ReversibleContainer, optional container requirements, and all requirements of AssociativeContainer (including logarithmic search complexity), except that:
- requirements related to nodes are not applicable,
- iterator invalidation requirements differ,
- the complexity of insertion and erasure operations is linear.
A flat multiset supports most AssociativeContainer's operations that use equal keys.
Contents |
[edit] Iterator invalidation
This section is incomplete |
[edit] Template parameters
Key | - | The type of the stored elements. The program is ill-formed if Key is not the same type as KeyContainer::value_type .
|
Compare | - | A Compare type providing a strict weak ordering. |
KeyContainer | - | The type of the underlying SequenceContainer to store the elements. The iterators of such container should satisfy LegacyRandomAccessIterator or model random_access_iterator .
The standard containers std::vector and std::deque satisfy these requirements. |
[edit] Member types
Type | Definition |
container_type
|
Key Container
|
key_type
|
Key
|
value_type
|
Key
|
key_compare
|
Compare
|
value_compare
|
Compare
|
reference
|
value_type& |
const_reference
|
const value_type& |
size_type
|
typename KeyContainer::size_type |
difference_type
|
typename KeyContainer::difference_type |
iterator
|
implementation-defined LegacyRandomAccessIterator and random_access_iterator to value_type
|
const_iterator
|
implementation-defined LegacyRandomAccessIterator and random_access_iterator to const value_type
|
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[edit] Member objects
Member | Description |
container_type c (private)
|
the adapted container (exposition-only member object*) |
key_compare compare (private)
|
the comparison function object (exposition-only member object*) |
[edit] Member functions
constructs the flat_multiset (public member function) | |
(destructor) (implicitly declared) |
destroys every element of the container adaptor (public member function) |
assigns values to the container adaptor (public member function) | |
Iterators | |
returns an iterator to the beginning (public member function) | |
returns an iterator to the end (public member function) | |
returns a reverse iterator to the beginning (public member function) | |
returns a reverse iterator to the end (public member function) | |
Capacity | |
checks whether the container adaptor is empty (public member function) | |
returns the number of elements (public member function) | |
returns the maximum possible number of elements (public member function) | |
Modifiers | |
constructs element in-place (public member function) | |
constructs elements in-place using a hint (public member function) | |
inserts elements (public member function) | |
inserts a range of elements (public member function) | |
extracts the underlying container (public member function) | |
replaces the underlying container (public member function) | |
erases elements (public member function) | |
swaps the contents (public member function) | |
clears the contents (public member function) | |
Lookup | |
finds element with specific key (public member function) | |
returns the number of elements matching specific key (public member function) | |
checks if the container contains element with specific key (public member function) | |
returns an iterator to the first element not less than the given key (public member function) | |
returns an iterator to the first element greater than the given key (public member function) | |
returns range of elements matching a specific key (public member function) | |
Observers | |
returns the function that compares keys (public member function) | |
returns the function that compares keys in objects of type value_type (public member function) |
[edit] Non-member functions
(C++23) |
lexicographically compares the values of two flat_multiset s (function template) |
specializes the std::swap algorithm (function template) | |
(C++23) |
erases all elements satisfying specific criteria (function template) |
[edit] Helper classes
specializes the std::uses_allocator type trait (class template specialization) |
[edit] Tags
indicates that elements of a range are sorted (uniqueness is not required) (tag) |
[edit] Deduction guides
[edit] Notes
The member types iterator
and const_iterator
may be aliases to the same type. This means defining a pair of function overloads using the two types as parameter types may violate the One Definition Rule. Since iterator
is convertible to const_iterator
, a single function with a const_iterator
as parameter type will work instead.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_flat_set |
202207L | (C++23) | std::flat_set and std::flat_multiset
|
[edit] Example
This section is incomplete Reason: no example |
[edit] See also
(C++23) |
adapts a container to provide a collection of unique keys, sorted by keys (class template) |
collection of keys, sorted by keys (class template) | |
(C++11) |
collection of keys, hashed by keys (class template) |