3 Forward declares `boost::hana::partition`.
5 @copyright Louis Dionne 2013-2016
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_PARTITION_HPP
11 #define BOOST_HANA_FWD_PARTITION_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/detail/nested_by_fwd.hpp>
19 BOOST_HANA_NAMESPACE_BEGIN
20 //! Partition a sequence based on a `predicate`.
21 //! @ingroup group-Sequence
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.
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:
34 //! \mathtt{partition} : S(T) \times (T \to Bool) \to S(T) \times S(T)
38 //! The sequence to be partitioned.
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`.
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:
53 //! partition.by(predicate, xs) == partition(xs, predicate)
54 //! partition.by(predicate) == partition(-, predicate)
57 //! where `partition(-, predicate)` denotes the partial application of
58 //! `partition` to `predicate`.
63 //! @include example/partition.cpp
64 #ifdef BOOST_HANA_DOXYGEN_INVOKED
65 constexpr auto partition = [](auto&& xs, auto&& predicate) {
66 return tag-dispatched;
69 template <typename S, typename = void>
70 struct partition_impl : partition_impl<S, when<true>> { };
72 struct partition_t : detail::nested_by<partition_t> {
73 template <typename Xs, typename Pred>
74 constexpr auto operator()(Xs&& xs, Pred&& pred) const;
77 constexpr partition_t partition{};
79 BOOST_HANA_NAMESPACE_END
81 #endif // !BOOST_HANA_FWD_PARTITION_HPP