]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/fwd/partition.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / hana / fwd / partition.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::partition`.
4
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)
8 */
9
10 #ifndef BOOST_HANA_FWD_PARTITION_HPP
11 #define BOOST_HANA_FWD_PARTITION_HPP
12
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/detail/nested_by_fwd.hpp>
16
17
18
19 BOOST_HANA_NAMESPACE_BEGIN
20 //! Partition a sequence based on a `predicate`.
21 //! @ingroup group-Sequence
22 //!
23 //! Specifically, returns an unspecified `Product` whose first element is
24 //! a sequence of the elements satisfying the predicate, and whose second
25 //! element is a sequence of the elements that do not satisfy the predicate.
26 //!
27 //!
28 //! Signature
29 //! ---------
30 //! Given a Sequence `S(T)`, an `IntegralConstant` `Bool` holding a value
31 //! of type `bool`, and a predicate \f$ T \to Bool \f$, `partition` has
32 //! the following signature:
33 //! \f[
34 //! \mathtt{partition} : S(T) \times (T \to Bool) \to S(T) \times S(T)
35 //! \f]
36 //!
37 //! @param xs
38 //! The sequence to be partitioned.
39 //!
40 //! @param predicate
41 //! A function called as `predicate(x)` for each element `x` in the
42 //! sequence, and returning whether `x` should be added to the sequence
43 //! in the first component or in the second component of the resulting
44 //! pair. In the current version of the library, `predicate` must return
45 //! an `IntegralConstant` holding a value convertible to `bool`.
46 //!
47 //!
48 //! Syntactic sugar (`partition.by`)
49 //! --------------------------------
50 //! `partition` can be called in an alternate way, which provides a nice
51 //! syntax in some cases where the predicate is short:
52 //! @code
53 //! partition.by(predicate, xs) == partition(xs, predicate)
54 //! partition.by(predicate) == partition(-, predicate)
55 //! @endcode
56 //!
57 //! where `partition(-, predicate)` denotes the partial application of
58 //! `partition` to `predicate`.
59 //!
60 //!
61 //! Example
62 //! -------
63 //! @include example/partition.cpp
64 #ifdef BOOST_HANA_DOXYGEN_INVOKED
65 constexpr auto partition = [](auto&& xs, auto&& predicate) {
66 return tag-dispatched;
67 };
68 #else
69 template <typename S, typename = void>
70 struct partition_impl : partition_impl<S, when<true>> { };
71
72 struct partition_t : detail::nested_by<partition_t> {
73 template <typename Xs, typename Pred>
74 constexpr auto operator()(Xs&& xs, Pred&& pred) const;
75 };
76
77 constexpr partition_t partition{};
78 #endif
79 BOOST_HANA_NAMESPACE_END
80
81 #endif // !BOOST_HANA_FWD_PARTITION_HPP