Basic unordered container requiring unique, Comparable and Hashable keys.
A set is an unordered container that can hold heterogeneous keys. A set requires (and ensures) that no duplicates are present when inserting new keys.
hana::set is implementation-defined. In particular, one should not take for granted the order of the template parameters and the presence of any additional constructors or assignment operators than what is documented. The canonical way of creating a hana::set is through hana::make_set.Comparablenothing. Also note that operator[] can be used instead of the at_key function. Foldable Any Foldable structure can be converted into a hana::set with to<set_tag>. The elements of the structure must all be compile-time Comparable. If the structure contains duplicate elements, only the first occurence will appear in the resulting set. More specifically, conversion from a Foldable is equivalent to
Example
Synopsis of associated functions | |
| template<> | |
| constexpr auto | make< set_tag > |
Function object for creating a hana::set. More... | |
| constexpr auto | make_set = make<set_tag> |
Equivalent to make<set_tag>; provided for convenience. More... | |
| constexpr auto | insert |
Insert an element in a hana::set. More... | |
| constexpr auto | erase_key |
Remove an element from a hana::set. More... | |
| constexpr auto | union_ |
| Returns the union of two sets. More... | |
| constexpr auto | intersection |
| Returns the intersection of two sets. More... | |
| constexpr auto | to_set = to<set_tag> |
Equivalent to to<set_tag>; provided for convenience. More... | |
| constexpr auto | difference |
| Returns the set-theoretic difference of two sets. More... | |
| constexpr auto | symmetric_difference |
| Returns the symmetric set-theoretic difference of two sets. More... | |
Friends | |
| template<typename X , typename Y > | |
| constexpr auto | operator== (X &&x, Y &&y) |
Equivalent to hana::equal | |
| template<typename X , typename Y > | |
| constexpr auto | operator!= (X &&x, Y &&y) |
Equivalent to hana::not_equal | |
Public Member Functions | |
| constexpr | set ()=default |
| Default-construct a set. This constructor only exists when all the elements of the set are default-constructible. | |
| constexpr | set (set const &other)=default |
| Copy-construct a set from another set. This constructor only exists when all the elements of the set are copy-constructible. | |
| constexpr | set (set &&other)=default |
| Move-construct a set from another set. This constructor only exists when all the elements of the set are move-constructible. | |
| template<typename Key > | |
| decltype(auto) constexpr | operator[] (Key &&key) |
Equivalent to hana::at_key | |
Function object for creating a hana::set.
Given zero or more values xs..., make<set_tag> returns a set containing those values. The values must all be compile-time Comparable, and no duplicate values may be provided. To create a set from a sequence with possible duplicates, use to<set_tag> instead.
Equivalent to make<set_tag>; provided for convenience.
|
related |
Insert an element in a hana::set.
If the set already contains an element that compares equal, then nothing is done and the set is returned as is.
| set | The set in which to insert a value. |
| element | The value to insert. It must be compile-time Comparable. |
|
related |
Remove an element from a hana::set.
Returns a new set containing all the elements of the original, except the one comparing equal to the given element. If the set does not contain such an element, a new set equal to the original set is returned.
| set | The set in which to remove a value. |
| element | The value to remove. It must be compile-time Comparable. |
|
related |
Returns the union of two sets.
Given two sets xs and ys, union_(xs, ys) is a new set containing all the elements of xs and all the elements of ys, without duplicates. For any object x, the following holds: x is in hana::union_(xs, ys) if and only if x is in xs or x is in ys.
| xs,ys | Two sets to compute the union of. |
|
related |
Returns the intersection of two sets.
Given two sets xs and ys, intersection(xs, ys) is a new set containing exactly those elements that are present both in xs and in ys. In other words, the following holds for any object x:
| xs,ys | Two sets to intersect. |
Equivalent to to<set_tag>; provided for convenience.
|
related |
Returns the set-theoretic difference of two sets.
Given two sets xs and ys, difference(xs, ys) is a new set containing all the elements of xs that are not contained in ys. For any object x, the following holds:
This operation is not commutative, i.e. difference(xs, ys) is not necessarily the same as difference(ys, xs). Indeed, consider the case where xs is empty and ys isn't. Then, difference(xs, ys) is empty but difference(ys, xs) is equal to ys. For the symmetric version of this operation, see symmetric_difference.
| xs | A set param to remove values from. |
| ys | The set whose values are removed from xs. |
|
related |
Returns the symmetric set-theoretic difference of two sets.
Given two sets xs and ys, symmetric_difference(xs, ys) is a new set containing all the elements of xs that are not contained in ys, and all the elements of ys that are not contained in xs. The symmetric difference of two sets satisfies the following:
| xs,ys | Two sets to compute the symmetric difference of. |