Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:04

0001 /*!
0002 @file
0003 Forward declares `boost::hana::partition`.
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_PARTITION_HPP
0011 #define BOOST_HANA_FWD_PARTITION_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 #include <boost/hana/detail/nested_by_fwd.hpp>
0016 
0017 
0018 
0019 namespace boost { namespace hana {
0020     //! Partition a sequence based on a `predicate`.
0021     //! @ingroup group-Sequence
0022     //!
0023     //! Specifically, returns an unspecified `Product` whose first element is
0024     //! a sequence of the elements satisfying the predicate, and whose second
0025     //! element is a sequence of the elements that do not satisfy the predicate.
0026     //!
0027     //!
0028     //! Signature
0029     //! ---------
0030     //! Given a Sequence `S(T)`, an `IntegralConstant` `Bool` holding a value
0031     //! of type `bool`, and a predicate \f$ T \to Bool \f$, `partition` has
0032     //! the following signature:
0033     //! \f[
0034     //!     \mathtt{partition} : S(T) \times (T \to Bool) \to S(T) \times S(T)
0035     //! \f]
0036     //!
0037     //! @param xs
0038     //! The sequence to be partitioned.
0039     //!
0040     //! @param predicate
0041     //! A function called as `predicate(x)` for each element `x` in the
0042     //! sequence, and returning whether `x` should be added to the sequence
0043     //! in the first component or in the second component of the resulting
0044     //! pair. In the current version of the library, `predicate` must return
0045     //! an `IntegralConstant` holding a value convertible to `bool`.
0046     //!
0047     //!
0048     //! Syntactic sugar (`partition.by`)
0049     //! --------------------------------
0050     //! `partition` can be called in an alternate way, which provides a nice
0051     //! syntax in some cases where the predicate is short:
0052     //! @code
0053     //!     partition.by(predicate, xs) == partition(xs, predicate)
0054     //!     partition.by(predicate) == partition(-, predicate)
0055     //! @endcode
0056     //!
0057     //! where `partition(-, predicate)` denotes the partial application of
0058     //! `partition` to `predicate`.
0059     //!
0060     //!
0061     //! Example
0062     //! -------
0063     //! @include example/partition.cpp
0064 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0065     constexpr auto partition = [](auto&& xs, auto&& predicate) {
0066         return tag-dispatched;
0067     };
0068 #else
0069     template <typename S, typename = void>
0070     struct partition_impl : partition_impl<S, when<true>> { };
0071 
0072     struct partition_t : detail::nested_by<partition_t> {
0073         template <typename Xs, typename Pred>
0074         constexpr auto operator()(Xs&& xs, Pred&& pred) const;
0075     };
0076 
0077     BOOST_HANA_INLINE_VARIABLE constexpr partition_t partition{};
0078 #endif
0079 }} // end namespace boost::hana
0080 
0081 #endif // !BOOST_HANA_FWD_PARTITION_HPP