Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Forward declares `boost::hana::span`.
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_SPAN_HPP
0011 #define BOOST_HANA_FWD_SPAN_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 namespace boost { namespace hana {
0019     //! Returns a `Product` containing the longest prefix of a sequence
0020     //! satisfying a predicate, and the rest of the sequence.
0021     //! @ingroup group-Sequence
0022     //!
0023     //! The first component of the returned `Product` is a sequence for which
0024     //! all elements satisfy the given predicate. The second component of the
0025     //! returned `Product` is a sequence containing the remainder of the
0026     //! argument. Both or either sequences may be empty, depending on the
0027     //! input argument. More specifically,
0028     //! @code
0029     //!     span(xs, predicate) == make_pair(take_while(xs, predicate),
0030     //!                                      drop_while(xs, predicate))
0031     //! @endcode
0032     //! except that `make_pair` may be an arbitrary `Product`.
0033     //!
0034     //!
0035     //! Signature
0036     //! ---------
0037     //! Given a `Sequence` `S(T)`, a `Logical` `Bool` and a predicate
0038     //! \f$ T \to Bool \f$, `span` has the following signature:
0039     //! \f[
0040     //!     \mathtt{span} : S(T) \times (T \to Bool) \to S(T) \times S(T)
0041     //! \f]
0042     //!
0043     //! @param xs
0044     //! The sequence to break into two parts.
0045     //!
0046     //! @param predicate
0047     //! A function called as `predicate(x)`, where `x` is an element of the
0048     //! sequence, and returning a `Logical. In the current implementation of
0049     //! the library, `predicate` has to return a compile-time `Logical`.
0050     //!
0051     //!
0052     //! Syntactic sugar (`span.by`)
0053     //! ---------------------------
0054     //! `span` can be called in an alternate way, which provides a nice syntax
0055     //! in some cases where the predicate is short:
0056     //! @code
0057     //!     span.by(predicate, xs) == span(xs, predicate)
0058     //!     span.by(predicate) == span(-, predicate)
0059     //! @endcode
0060     //!
0061     //! where `span(-, predicate)` denotes the partial application of
0062     //! `span` to `predicate`.
0063     //!
0064     //!
0065     //! Example
0066     //! -------
0067     //! @include example/span.cpp
0068 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0069     constexpr auto span = [](auto&& xs, auto&& predicate) {
0070         return tag-dispatched;
0071     };
0072 #else
0073     template <typename S, typename = void>
0074     struct span_impl : span_impl<S, when<true>> { };
0075 
0076     struct span_t : detail::nested_by<span_t> {
0077         template <typename Xs, typename Pred>
0078         constexpr auto operator()(Xs&& xs, Pred&& pred) const;
0079     };
0080 
0081     BOOST_HANA_INLINE_VARIABLE constexpr span_t span{};
0082 #endif
0083 }} // end namespace boost::hana
0084 
0085 #endif // !BOOST_HANA_FWD_SPAN_HPP