3 Forward declares `boost::hana::set`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FWD_SET_HPP
11 #define BOOST_HANA_FWD_SET_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/to.hpp>
15 #include <boost/hana/fwd/core/make.hpp>
16 #include <boost/hana/fwd/erase_key.hpp>
19 namespace boost { namespace hana {
20 //! @ingroup group-datatypes
21 //! Basic unordered container requiring unique, `Comparable` and
24 //! A set is an unordered container that can hold heterogeneous keys.
25 //! A set requires (and ensures) that no duplicates are present when
26 //! inserting new keys.
29 //! The actual representation of a `hana::set` is implementation-defined.
30 //! In particular, one should not take for granted the order of the
31 //! template parameters and the presence of any additional constructors
32 //! or assignment operators than what is documented. The canonical way of
33 //! creating a `hana::set` is through `hana::make_set`. More details
34 //! [in the tutorial](@ref tutorial-containers-types).
40 //! Two sets are equal iff they contain the same elements, regardless of
42 //! @include example/set/comparable.cpp
45 //! Folding a set is equivalent to folding the sequence of its values.
46 //! However, note that the values are not required to be in any specific
47 //! order, so using the folds provided here with an operation that is not
48 //! both commutative and associative will yield non-deterministic behavior.
49 //! @include example/set/foldable.cpp
52 //! The elements in a set act as both its keys and its values. Since the
53 //! elements of a set are unique, searching for an element will return
54 //! either the only element which is equal to the searched value, or
55 //! `nothing`. Also note that `operator[]` can be used instead of the
56 //! `at_key` function.
57 //! @include example/set/searchable.cpp
60 //! Conversion from any `Foldable`
61 //! ------------------------------
62 //! Any `Foldable` structure can be converted into a `hana::set` with
63 //! `to<set_tag>`. The elements of the structure must all be compile-time
64 //! `Comparable`. If the structure contains duplicate elements, only
65 //! the first occurence will appear in the resulting set. More
66 //! specifically, conversion from a `Foldable` is equivalent to
68 //! to<set_tag>(xs) == fold_left(xs, make_set(), insert)
72 //! @include example/set/to.cpp
73 #ifdef BOOST_HANA_DOXYGEN_INVOKED
74 template <typename implementation_defined>
76 //! Default-construct a set. This constructor only exists when all the
77 //! elements of the set are default-constructible.
78 constexpr set() = default;
80 //! Copy-construct a set from another set. This constructor only
81 //! exists when all the elements of the set are copy-constructible.
82 constexpr set(set const& other) = default;
84 //! Move-construct a set from another set. This constructor only
85 //! exists when all the elements of the set are move-constructible.
86 constexpr set(set&& other) = default;
88 //! Equivalent to `hana::equal`
89 template <typename X, typename Y>
90 friend constexpr auto operator==(X&& x, Y&& y);
92 //! Equivalent to `hana::not_equal`
93 template <typename X, typename Y>
94 friend constexpr auto operator!=(X&& x, Y&& y);
96 //! Equivalent to `hana::at_key`
97 template <typename Key>
98 constexpr decltype(auto) operator[](Key&& key);
101 template <typename ...Xs>
105 //! Tag representing the `hana::set` container.
106 //! @relates hana::set
109 //! Function object for creating a `hana::set`.
110 //! @relates hana::set
112 //! Given zero or more values `xs...`, `make<set_tag>` returns a `set`
113 //! containing those values. The values must all be compile-time
114 //! `Comparable`, and no duplicate values may be provided. To create
115 //! a `set` from a sequence with possible duplicates, use `to<set_tag>`
121 //! @include example/set/make.cpp
122 #ifdef BOOST_HANA_DOXYGEN_INVOKED
124 constexpr auto make<set_tag> = [](auto&& ...xs) {
125 return set<implementation_defined>{forwarded(xs)...};
129 //! Equivalent to `make<set_tag>`; provided for convenience.
130 //! @relates hana::set
135 //! @include example/set/make.cpp
136 BOOST_HANA_INLINE_VARIABLE constexpr auto make_set = make<set_tag>;
138 //! Insert an element in a `hana::set`.
139 //! @relates hana::set
141 //! If the set already contains an element that compares equal, then
142 //! nothing is done and the set is returned as is.
146 //! The set in which to insert a value.
149 //! The value to insert. It must be compile-time `Comparable`.
154 //! @include example/set/insert.cpp
155 #ifdef BOOST_HANA_DOXYGEN_INVOKED
156 constexpr auto insert = [](auto&& set, auto&& element) {
157 return tag-dispatched;
161 //! Remove an element from a `hana::set`.
162 //! @relates hana::set
164 //! Returns a new set containing all the elements of the original,
165 //! except the one comparing `equal` to the given element. If the set
166 //! does not contain such an element, a new set equal to the original
171 //! The set in which to remove a value.
174 //! The value to remove. It must be compile-time `Comparable`.
179 //! @include example/set/erase_key.cpp
180 #ifdef BOOST_HANA_DOXYGEN_INVOKED
181 constexpr auto erase_key = [](auto&& set, auto&& element) {
182 return tag-dispatched;
186 //! Returns the union of two sets.
187 //! @relates hana::set
189 //! Given two sets `xs` and `ys`, `union_(xs, ys)` is a new set containing
190 //! all the elements of `xs` and all the elements of `ys`, without
191 //! duplicates. For any object `x`, the following holds: `x` is in
192 //! `hana::union_(xs, ys)` if and only if `x` is in `xs` or `x` is in `ys`.
196 //! Two sets to compute the union of.
201 //! @include example/set/union.cpp
202 #ifdef BOOST_HANA_DOXYGEN_INVOKED
203 constexpr auto union_ = [](auto&& xs, auto&& ys) {
204 return tag-dispatched;
208 //! Returns the intersection of two sets.
209 //! @relates hana::set
211 //! Given two sets `xs` and `ys`, `intersection(xs, ys)` is a new set
212 //! containing exactly those elements that are present both in `xs` and
214 //! In other words, the following holds for any object `x`:
216 //! x ^in^ intersection(xs, ys) if and only if x ^in^ xs && x ^in^ ys
221 //! Two sets to intersect.
226 //! @include example/set/intersection.cpp
227 #ifdef BOOST_HANA_DOXYGEN_INVOKED
228 constexpr auto intersection = [](auto&& xs, auto&& ys) {
229 return tag-dispatched;
232 //! Equivalent to `to<set_tag>`; provided for convenience.
233 //! @relates hana::set
234 constexpr auto to_set = to<set_tag>;
236 //! Returns the set-theoretic difference of two sets.
237 //! @relates hana::set
239 //! Given two sets `xs` and `ys`, `difference(xs, ys)` is a new set
240 //! containing all the elements of `xs` that are _not_ contained in `ys`.
241 //! For any object `x`, the following holds:
243 //! x ^in^ difference(xs, ys) if and only if x ^in^ xs && !(x ^in^ ys)
247 //! This operation is not commutative, i.e. `difference(xs, ys)` is not
248 //! necessarily the same as `difference(ys, xs)`. Indeed, consider the
249 //! case where `xs` is empty and `ys` isn't. Then, `difference(xs, ys)`
250 //! is empty but `difference(ys, xs)` is equal to `ys`. For the symmetric
251 //! version of this operation, see `symmetric_difference`.
255 //! A set param to remove values from.
258 //! The set whose values are removed from `xs`.
263 //! @include example/set/difference.cpp
264 #ifdef BOOST_HANA_DOXYGEN_INVOKED
265 constexpr auto difference = [](auto&& xs, auto&& ys) {
266 return tag-dispatched;
270 //! Returns the symmetric set-theoretic difference of two sets.
271 //! @relates hana::set
273 //! Given two sets `xs` and `ys`, `symmetric_difference(xs, ys)` is a new
274 //! set containing all the elements of `xs` that are not contained in `ys`,
275 //! and all the elements of `ys` that are not contained in `xs`. The
276 //! symmetric difference of two sets satisfies the following:
278 //! symmetric_difference(xs, ys) == union_(difference(xs, ys), difference(ys, xs))
283 //! Two sets to compute the symmetric difference of.
288 //! @include example/set/symmetric_difference.cpp
289 #ifdef BOOST_HANA_DOXYGEN_INVOKED
290 constexpr auto symmetric_difference = [](auto&& xs, auto&& ys) {
291 return tag-dispatched;
296 }} // end namespace boost::hana
298 #endif // !BOOST_HANA_FWD_SET_HPP