Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:13:44

0001 /*!
0002 @file
0003 Forward declares `boost::hana::set`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_SET_HPP
0011 #define BOOST_HANA_FWD_SET_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/fwd/core/to.hpp>
0015 #include <boost/hana/fwd/core/make.hpp>
0016 #include <boost/hana/fwd/erase_key.hpp>
0017 
0018 
0019 namespace boost { namespace hana {
0020     //! @ingroup group-datatypes
0021     //! Basic unordered container requiring unique, `Comparable` and
0022     //! `Hashable` keys.
0023     //!
0024     //! A set is an unordered container that can hold heterogeneous keys.
0025     //! A set requires (and ensures) that no duplicates are present when
0026     //! inserting new keys.
0027     //!
0028     //! @note
0029     //! The actual representation of a `hana::set` is implementation-defined.
0030     //! In particular, one should not take for granted the order of the
0031     //! template parameters and the presence of any additional constructors
0032     //! or assignment operators than what is documented. The canonical way of
0033     //! creating a `hana::set` is through `hana::make_set`. More details
0034     //! [in the tutorial](@ref tutorial-containers-types).
0035     //!
0036     //!
0037     //! Modeled concepts
0038     //! ----------------
0039     //! 1. `Comparable`\n
0040     //! Two sets are equal iff they contain the same elements, regardless of
0041     //! the order.
0042     //! @include example/set/comparable.cpp
0043     //!
0044     //! 2. Foldable\n
0045     //! Folding a set is equivalent to folding the sequence of its values.
0046     //! However, note that the values are not required to be in any specific
0047     //! order, so using the folds provided here with an operation that is not
0048     //! both commutative and associative will yield non-deterministic behavior.
0049     //! @include example/set/foldable.cpp
0050     //!
0051     //! 3. Searchable\n
0052     //! The elements in a set act as both its keys and its values. Since the
0053     //! elements of a set are unique, searching for an element will return
0054     //! either the only element which is equal to the searched value, or
0055     //! `nothing`. Also note that `operator[]` can be used instead of the
0056     //! `at_key` function.
0057     //! @include example/set/searchable.cpp
0058     //!
0059     //!
0060     //! Conversion from any `Foldable`
0061     //! ------------------------------
0062     //! Any `Foldable` structure can be converted into a `hana::set` with
0063     //! `to<set_tag>`. The elements of the structure must all be compile-time
0064     //! `Comparable`. If the structure contains duplicate elements, only
0065     //! the first occurence will appear in the resulting set. More
0066     //! specifically, conversion from a `Foldable` is equivalent to
0067     //! @code
0068     //!     to<set_tag>(xs) == fold_left(xs, make_set(), insert)
0069     //! @endcode
0070     //!
0071     //! __Example__
0072     //! @include example/set/to.cpp
0073 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0074     template <typename implementation_defined>
0075     struct set {
0076         //! Default-construct a set. This constructor only exists when all the
0077         //! elements of the set are default-constructible.
0078         constexpr set() = default;
0079 
0080         //! Copy-construct a set from another set. This constructor only
0081         //! exists when all the elements of the set are copy-constructible.
0082         constexpr set(set const& other) = default;
0083 
0084         //! Move-construct a set from another set. This constructor only
0085         //! exists when all the elements of the set are move-constructible.
0086         constexpr set(set&& other) = default;
0087 
0088         //! Equivalent to `hana::equal`
0089         template <typename X, typename Y>
0090         friend constexpr auto operator==(X&& x, Y&& y);
0091 
0092         //! Equivalent to `hana::not_equal`
0093         template <typename X, typename Y>
0094         friend constexpr auto operator!=(X&& x, Y&& y);
0095 
0096         //! Equivalent to `hana::at_key`
0097         template <typename Key>
0098         constexpr decltype(auto) operator[](Key&& key);
0099     };
0100 #else
0101     template <typename ...Xs>
0102     struct set;
0103 #endif
0104 
0105     //! Tag representing the `hana::set` container.
0106     //! @relates hana::set
0107     struct set_tag { };
0108 
0109     //! Function object for creating a `hana::set`.
0110     //! @relates hana::set
0111     //!
0112     //! Given zero or more values `xs...`, `make<set_tag>` returns a `set`
0113     //! containing those values. The values must all be compile-time
0114     //! `Comparable`, and no duplicate values may be provided. To create
0115     //! a `set` from a sequence with possible duplicates, use `to<set_tag>`
0116     //! instead.
0117     //!
0118     //!
0119     //! Example
0120     //! -------
0121     //! @include example/set/make.cpp
0122 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0123     template <>
0124     constexpr auto make<set_tag> = [](auto&& ...xs) {
0125         return set<implementation_defined>{forwarded(xs)...};
0126     };
0127 #endif
0128 
0129     //! Equivalent to `make<set_tag>`; provided for convenience.
0130     //! @relates hana::set
0131     //!
0132     //!
0133     //! Example
0134     //! -------
0135     //! @include example/set/make.cpp
0136     BOOST_HANA_INLINE_VARIABLE constexpr auto make_set = make<set_tag>;
0137 
0138     //! Insert an element in a `hana::set`.
0139     //! @relates hana::set
0140     //!
0141     //! If the set already contains an element that compares equal, then
0142     //! nothing is done and the set is returned as is.
0143     //!
0144     //!
0145     //! @param set
0146     //! The set in which to insert a value.
0147     //!
0148     //! @param element
0149     //! The value to insert. It must be compile-time `Comparable`.
0150     //!
0151     //!
0152     //! Example
0153     //! -------
0154     //! @include example/set/insert.cpp
0155 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0156     constexpr auto insert = [](auto&& set, auto&& element) {
0157         return tag-dispatched;
0158     };
0159 #endif
0160 
0161     //! Remove an element from a `hana::set`.
0162     //! @relates hana::set
0163     //!
0164     //! Returns a new set containing all the elements of the original,
0165     //! except the one comparing `equal` to the given element. If the set
0166     //! does not contain such an element, a new set equal to the original
0167     //! set is returned.
0168     //!
0169     //!
0170     //! @param set
0171     //! The set in which to remove a value.
0172     //!
0173     //! @param element
0174     //! The value to remove. It must be compile-time `Comparable`.
0175     //!
0176     //!
0177     //! Example
0178     //! -------
0179     //! @include example/set/erase_key.cpp
0180 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0181     constexpr auto erase_key = [](auto&& set, auto&& element) {
0182         return tag-dispatched;
0183     };
0184 #endif
0185 
0186     //! Returns the union of two sets.
0187     //! @relates hana::set
0188     //!
0189     //! Given two sets `xs` and `ys`, `union_(xs, ys)` is a new set containing
0190     //! all the elements of `xs` and all the elements of `ys`, without
0191     //! duplicates. For any object `x`, the following holds: `x` is in
0192     //! `hana::union_(xs, ys)` if and only if `x` is in `xs` or `x` is in `ys`.
0193     //!
0194     //!
0195     //! @param xs, ys
0196     //! Two sets to compute the union of.
0197     //!
0198     //!
0199     //! Example
0200     //! -------
0201     //! @include example/set/union.cpp
0202 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0203     constexpr auto union_ = [](auto&& xs, auto&& ys) {
0204         return tag-dispatched;
0205     };
0206 #endif
0207 
0208     //! Returns the intersection of two sets.
0209     //! @relates hana::set
0210     //!
0211     //! Given two sets `xs` and `ys`, `intersection(xs, ys)` is a new set
0212     //! containing exactly those elements that are present both in `xs` and
0213     //! in `ys`.
0214     //! In other words, the following holds for any object `x`:
0215     //! @code
0216     //!     x ^in^ intersection(xs, ys) if and only if x ^in^ xs && x ^in^ ys
0217     //! @endcode
0218     //!
0219     //!
0220     //! @param xs, ys
0221     //! Two sets to intersect.
0222     //!
0223     //!
0224     //! Example
0225     //! -------
0226     //! @include example/set/intersection.cpp
0227 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0228     constexpr auto intersection = [](auto&& xs, auto&& ys) {
0229         return tag-dispatched;
0230     };
0231 #endif
0232     //! Equivalent to `to<set_tag>`; provided for convenience.
0233     //! @relates hana::set
0234     constexpr auto to_set = to<set_tag>;
0235 
0236     //! Returns the set-theoretic difference of two sets.
0237     //! @relates hana::set
0238     //!
0239     //! Given two sets `xs` and `ys`, `difference(xs, ys)` is a new set
0240     //! containing all the elements of `xs` that are _not_ contained in `ys`.
0241     //! For any object `x`, the following holds:
0242     //! @code
0243     //!     x ^in^ difference(xs, ys) if and only if x ^in^ xs && !(x ^in^ ys)
0244     //! @endcode
0245     //!
0246     //!
0247     //! This operation is not commutative, i.e. `difference(xs, ys)` is not
0248     //! necessarily the same as `difference(ys, xs)`. Indeed, consider the
0249     //! case where `xs` is empty and `ys` isn't. Then, `difference(xs, ys)`
0250     //! is empty but `difference(ys, xs)` is equal to `ys`. For the symmetric
0251     //! version of this operation, see `symmetric_difference`.
0252     //!
0253     //!
0254     //! @param xs
0255     //! A set param to remove values from.
0256     //!
0257     //! @param ys
0258     //! The set whose values are removed from `xs`.
0259     //!
0260     //!
0261     //! Example
0262     //! -------
0263     //! @include example/set/difference.cpp
0264 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0265     constexpr auto difference = [](auto&& xs, auto&& ys) {
0266         return tag-dispatched;
0267 };
0268 #endif
0269 
0270     //! Returns the symmetric set-theoretic difference of two sets.
0271     //! @relates hana::set
0272     //!
0273     //! Given two sets `xs` and `ys`, `symmetric_difference(xs, ys)` is a new
0274     //! set containing all the elements of `xs` that are not contained in `ys`,
0275     //! and all the elements of `ys` that are not contained in `xs`. The
0276     //! symmetric difference of two sets satisfies the following:
0277     //! @code
0278     //!     symmetric_difference(xs, ys) == union_(difference(xs, ys), difference(ys, xs))
0279     //! @endcode
0280     //!
0281     //!
0282     //! @param xs, ys
0283     //! Two sets to compute the symmetric difference of.
0284     //!
0285     //!
0286     //! Example
0287     //! -------
0288     //! @include example/set/symmetric_difference.cpp
0289 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0290 constexpr auto symmetric_difference = [](auto&& xs, auto&& ys) {
0291         return tag-dispatched;
0292     };
0293 #endif
0294 
0295 
0296 }} // end namespace boost::hana
0297 
0298 #endif // !BOOST_HANA_FWD_SET_HPP