 |
Boost.Hana
1.7.0
Your standard library for metaprogramming
|
|
template<typename implementation_defined>
struct boost::hana::set< implementation_defined >
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.
- Note
- The actual representation of a
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
. More details in the tutorial.
Modeled concepts
Comparable
Two sets are equal iff they contain the same elements, regardless of the order.
int main() {
hana::make_set(hana::int_c<0>, hana::type_c<char>, hana::int_c<1>)
==
hana::make_set(hana::int_c<1>, hana::int_c<0>, hana::type_c<char>)
);
hana::make_set(hana::int_c<0>, hana::type_c<char>)
!=
hana::make_set(hana::int_c<1>)
);
}
- Foldable
Folding a set is equivalent to folding the sequence of its values. However, note that the values are not required to be in any specific order, so using the folds provided here with an operation that is not both commutative and associative will yield non-deterministic behavior.
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>);
static_assert(hana::minimum(xs) == hana::int_c<0>, "");
static_assert(hana::maximum(xs) == hana::int_c<2>, "");
static_assert(hana::sum<>(xs) == hana::int_c<3>, "");
}
- Searchable
The elements in a set act as both its keys and its values. Since the elements of a set are unique, searching for an element will return either the only element which is equal to the searched value, or nothing
. Also note that operator[]
can be used instead of the at_key
function.
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::int_c<1>, hana::int_c<2>);
}
Conversion from any <tt>Foldable</tt>
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
int main() {
constexpr auto xs = hana::make_tuple(
hana::int_c<1>,
hana::int_c<3>,
hana::type_c<int>,
hana::long_c<1>
);
hana::to<hana::set_tag>(xs)
==
hana::make_set(hana::int_c<1>, hana::int_c<3>, hana::type_c<int>)
);
}
|
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 > |
constexpr decltype(auto) | operator[] (Key &&key) |
| Equivalent to hana::at_key
|
|
◆ make< set_tag >
template<typename implementation_defined >
template<>
Initial value:= [](auto&& ...xs) {
return set<implementation_defined>{forwarded(xs)...};
}
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.
Example
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>);
int main() { }
◆ make_set
template<typename implementation_defined >
Equivalent to make<set_tag>
; provided for convenience.
Example
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>);
int main() { }
◆ insert
template<typename implementation_defined >
Initial value:= [](
auto&&
set,
auto&& element) {
return tag-dispatched;
}
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.
- Parameters
-
set | The set in which to insert a value. |
element | The value to insert. It must be compile-time Comparable . |
Example
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::type_c<int>);
hana::make_set(hana::int_c<0>, hana::type_c<int>, BOOST_HANA_STRING("abc"))
);
hana::insert(xs, hana::int_c<0>) == hana::make_set(hana::int_c<0>, hana::type_c<int>)
);
}
◆ erase_key
template<typename implementation_defined >
Initial value:= [](
auto&&
set,
auto&& element) {
return tag-dispatched;
}
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.
- Parameters
-
set | The set in which to remove a value. |
element | The value to remove. It must be compile-time Comparable . |
Example
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::type_c<int>, hana::type_c<void>);
}
◆ union_
template<typename implementation_defined >
Initial value:= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}
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
.
- Parameters
-
xs,ys | Two sets to compute the union of. |
Example
using namespace hana::literals;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>, hana::int_c<2>);
constexpr auto ys = hana::make_set(hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
hana::int_c<1>, hana::int_c<2>, hana::int_c<3>, hana::type_c<void>, hana::type_c<int>
));
int main() { }
◆ intersection
template<typename implementation_defined >
constexpr auto intersection |
|
related |
Initial value:= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}
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
:
- Parameters
-
xs,ys | Two sets to intersect. |
Example
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>, hana::int_c<2>);
constexpr auto ys = hana::make_set(hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
int main() { }
◆ difference
template<typename implementation_defined >
constexpr auto difference |
|
related |
Initial value:= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}
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
.
- Parameters
-
xs | A set param to remove values from. |
ys | The set whose values are removed from xs . |
Example
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
constexpr auto ys = hana::make_set(hana::int_c<3>, hana::type_c<void>, hana::type_c<int>);
int main() { }
◆ symmetric_difference
template<typename implementation_defined >
constexpr auto symmetric_difference |
|
related |
Initial value:= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}
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:
- Parameters
-
xs,ys | Two sets to compute the symmetric difference of. |
Example
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
constexpr auto ys = hana::make_set(hana::int_c<3>, hana::type_c<void>, hana::type_c<int>);
hana::symmetric_difference(xs, ys) == hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<void>)
);
int main() { }
Defines boost::hana::equal.
#define BOOST_HANA_CONSTANT_CHECK(...)
Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
Definition: assert.hpp:239
constexpr set()=default
Default-construct a set. This constructor only exists when all the elements of the set are default-co...
Defines boost::hana::tuple.
Defines boost::hana::set.
Defines boost::hana::integral_constant.
constexpr auto difference
Returns the set-theoretic difference of two sets.
Definition: set.hpp:265
Defines boost::hana::make.
constexpr auto find
Finds the value associated to the given key in a structure.
Definition: find.hpp:44
Defines boost::hana::find.
constexpr insert_t insert
Insert a value at a given index in a sequence.
Definition: insert.hpp:29
constexpr auto insert
Insert an element in a hana::set.
Definition: set.hpp:156
constexpr auto symmetric_difference
Returns the symmetric set-theoretic difference of two sets.
Definition: set.hpp:290
constexpr auto union_
Returns the union of two sets.
Definition: set.hpp:203
Defines boost::hana::string.
Defines boost::hana::erase_key.
Defines boost::hana::intersection.
Defines boost::hana::type and related utilities.
Defines boost::hana::maximum.
Namespace containing everything in the library.
Definition: accessors.hpp:20
constexpr auto in
Return whether the key occurs in the structure.
Definition: contains.hpp:70
Defines macros to perform different kinds of assertions.
Defines boost::hana::to and related utilities.
constexpr auto intersection
Returns the intersection of two sets.
Definition: set.hpp:228
Defines boost::hana::not_equal.
Defines boost::hana::difference.
Defines boost::hana::sum.
Defines boost::hana::symmetric_difference.
Defines boost::hana::at_key.
Defines boost::hana::minimum.
Defines boost::hana::insert.
constexpr auto make_set
Equivalent to make<set_tag>; provided for convenience.
Definition: set.hpp:136
Defines boost::hana::union.
Defines boost::hana::optional.