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>)
);
}
Defines macros to perform different kinds of assertions.
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
Defines boost::hana::integral_constant.
Namespace containing everything in the library.
Definition: accessors.hpp:20
Defines boost::hana::not_equal.
Defines boost::hana::set.
Defines boost::hana::type and related utilities.
- 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>, "");
}
Defines boost::hana::maximum.
Defines boost::hana::minimum.
Defines boost::hana::sum.
- 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>);
}
Defines boost::hana::at_key.
Defines boost::hana::find.
constexpr auto find
Finds the value associated to the given key in a structure.
Definition: find.hpp:44
Defines boost::hana::optional.
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
constexpr auto insert
Insert an element in a hana::set.
Definition: set.hpp:156
constexpr auto make_set
Equivalent to make<set_tag>; provided for convenience.
Definition: set.hpp:136
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>)
);
}
Defines boost::hana::to and related utilities.
Defines boost::hana::tuple.
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() { }
Defines boost::hana::union.
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:
constexpr auto difference
Returns the set-theoretic difference of two sets.
Definition: set.hpp:265
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() { }
Defines boost::hana::difference.