Basic associative container requiring unique, Comparable
and Hashable
keys.
The order of the elements of the map is unspecified. Also, all the keys must be Hashable
, and any two keys with equal hashes must be Comparable
with each other at compile-time.
hana::map
is an implementation detail. As such, one should not assume anything more than what is explicitly documented as being part of the interface of a map, such as:hana::map<Pairs...>
is, or is not, a dependent typehana::map<Pairs...>
is basically equivalent to Comparable
Searchable
Logical
. Also note that operator[]
can be used instead of at_key
. Foldable
Any Foldable
of Product
s can be converted to a hana::map
with hana::to<hana::map_tag>
or, equivalently, hana::to_map
. If the Foldable
contains duplicate keys, only the value associated to the first occurence of each key is kept.
Synopsis of associated functions | |
template<> | |
constexpr auto | make< map_tag > |
Function object for creating a hana::map . More... | |
constexpr auto | make_map = make<map_tag> |
Alias to make<map_tag> ; provided for convenience. More... | |
constexpr auto | to_map = to<map_tag> |
Equivalent to to<map_tag> ; provided for convenience. | |
constexpr auto | keys |
Returns a Sequence of the keys of the map, in unspecified order. More... | |
constexpr auto | values |
Returns a Sequence of the values of the map, in unspecified order. More... | |
constexpr auto | insert |
Inserts a new key/value pair in a map. More... | |
constexpr auto | erase_key |
Removes a key/value pair from a map. More... | |
constexpr auto | union_ |
Returns the union of two maps. More... | |
constexpr auto | intersection |
Returns the intersection of two maps. More... | |
constexpr auto | difference |
Returns the difference of two maps. More... | |
constexpr auto | symmetric_difference |
Returns the symmetric set-theoretic difference of two maps. More... | |
Friends | |
template<typename X , typename Y > | |
constexpr friend auto | operator== (X &&x, Y &&y) |
Equivalent to hana::equal | |
template<typename X , typename Y > | |
constexpr friend auto | operator!= (X &&x, Y &&y) |
Equivalent to hana::not_equal | |
Public Member Functions | |
constexpr | map ()=default |
Default-construct a map. This constructor only exists when all the elements of the map are default-constructible. | |
constexpr | map (map const &other)=default |
Copy-construct a map from another map. This constructor only exists when all the elements of the map are copy-constructible. | |
constexpr | map (map &&other)=default |
Move-construct a map from another map. This constructor only exists when all the elements of the map are move-constructible. | |
template<typename ... P> | |
constexpr | map (P &&...pairs) |
Construct the map from the provided pairs. P... must be pairs of the same type (modulo ref and cv-qualifiers), and in the same order, as those appearing in Pairs... . The pairs provided to this constructor are emplaced into the map's storage using perfect forwarding. | |
constexpr map & | operator= (map const &other) |
Assign a map to another map with the exact same type. Only exists when all the elements of the map are copy-assignable. | |
constexpr map & | operator= (map &&other) |
Move-assign a map to another map with the exact same type. Only exists when all the elements of the map are move-assignable. | |
template<typename Key > | |
constexpr decltype(auto) | operator[] (Key &&key) |
Equivalent to hana::at_key | |
Function object for creating a hana::map
.
Given zero or more Product
s representing key/value associations, make<map_tag>
returns a hana::map
associating these keys to these values.
make<map_tag>
requires all the keys to be unique and to have different hashes. If you need to create a map with duplicate keys or with keys whose hashes might collide, use hana::to_map
or insert (key, value)
pairs to an empty map successively. However, be aware that doing so will be much more compile-time intensive than using make<map_tag>
, because the uniqueness of keys will have to be enforced.
Alias to make<map_tag>
; provided for convenience.
|
related |
Returns a Sequence
of the keys of the map, in unspecified order.
|
related |
Returns a Sequence
of the values of the map, in unspecified order.
|
related |
Inserts a new key/value pair in a map.
Given a (key, value)
pair, insert
inserts this new pair into a map. If the map already contains this key, nothing is done and the map is returned as-is.
map | The map in which to insert a (key,value) pair. |
pair | An arbitrary Product representing a (key, value) pair to insert in the map. The key must be compile-time Comparable . |
|
related |
Removes a key/value pair from a map.
Returns a new hana::map
containing all the elements of the original, except for the (key, value)
pair whose key
compares equal
to the given key. If the map does not contain such an element, a new map equal to the original is returned.
map | The map in which to erase a key . |
key | A key to remove from the map. It must be compile-time Comparable . |
|
related |
Returns the union of two maps.
Given two maps xs
and ys
, hana::union_(xs, ys)
is a new map containing all the elements of xs
and all the elements of ys
, without duplicates. If both xs
and ys
contain an element with the same key
, the one in ys
is taken. Functionally, hana::union_(xs, ys)
is equivalent to
xs,ys | The two maps to compute the union of. |
|
related |
Returns the intersection of two maps.
Given two maps xs
and ys
, intersection(xs, ys)
is a new map containing exactly those (key, value) pairs from xs, for which key is present in ys
. In other words, the following holds for any object pair(k, v)
:
intersection(xs, ys)
is not necessarily the same as intersection(ys, xs)
. Indeed, the set of keys in intersection(xs, ys)
is always the same as the set of keys in intersection(ys, xs)
, but the value associated to each key may be different. intersection(xs, ys)
contains values present in xs
, and intersection(ys, xs)
contains values present in ys
.xs,ys | Two maps to intersect. |
|
related |
Returns the difference of two maps.
Given two maps xs
and ys
, difference(xs, ys)
is a new map containing exactly those (key, value) pairs from xs, for which key is not present in keys(ys)
. In other words, the following holds for any object pair(k, v)
:
difference(xs, ys)
is not necessarily the same as difference(ys, xs)
. Indeed, consider the case where xs
is empty and ys
isn't. In that case, difference(xs, ys)
is empty, but difference(ys, xs)
is equal to ys
. For symmetric version of this operation, see symmetric_difference
.xs,ys | Two maps to compute the difference of. |
|
related |
Returns the symmetric set-theoretic difference of two maps.
Given two sets xs
and ys
, symmetric_difference(xs, ys)
is a new map containing all the elements of xs
whose keys are not contained in keys(ys)
, and all the elements of ys
whose keys are not contained in keys(xs)
. The symmetric difference of two maps satisfies the following:
xs,ys | Two maps to compute the symmetric difference of. |