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::minimum`.
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_MINIMUM_HPP
0011 #define BOOST_HANA_FWD_MINIMUM_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     //! Return the least element of a non-empty structure with respect to
0020     //! a `predicate`, by default `less`.
0021     //! @ingroup group-Foldable
0022     //!
0023     //! Given a non-empty structure and an optional binary predicate
0024     //! (`less` by default), `minimum` returns the least element of
0025     //! the structure, i.e. an element which is less than or equal to
0026     //! every other element in the structure, according to the predicate.
0027     //!
0028     //! If the structure contains heterogeneous objects, then the predicate
0029     //! must return a compile-time `Logical`. If no predicate is provided,
0030     //! the elements in the structure must be Orderable, or compile-time
0031     //! Orderable if the structure is heterogeneous.
0032     //!
0033     //!
0034     //! Signature
0035     //! ---------
0036     //! Given a `Foldable` `F`, a Logical `Bool` and a predicate
0037     //! \f$ \mathtt{pred} : T \times T \to Bool \f$, `minimum` has the
0038     //! following signatures. For the variant with a provided predicate,
0039     //! \f[
0040     //!     \mathtt{minimum} : F(T) \times (T \times T \to Bool) \to T
0041     //! \f]
0042     //!
0043     //! for the variant without a custom predicate, `T` is required to be
0044     //! Orderable. The signature is then
0045     //! \f[
0046     //!     \mathtt{minimum} : F(T) \to T
0047     //! \f]
0048     //!
0049     //! @param xs
0050     //! The structure to find the least element of.
0051     //!
0052     //! @param predicate
0053     //! A function called as `predicate(x, y)`, where `x` and `y` are elements
0054     //! of the structure. `predicate` should be a strict weak ordering on the
0055     //! elements of the structure and its return value should be a Logical,
0056     //! or a compile-time Logical if the structure is heterogeneous.
0057     //!
0058     //! ### Example
0059     //! @include example/minimum.cpp
0060     //!
0061     //!
0062     //! Syntactic sugar (`minimum.by`)
0063     //! ------------------------------
0064     //! `minimum` can be called in a third way, which provides a nice syntax
0065     //! especially when working with the `ordering` combinator:
0066     //! @code
0067     //!     minimum.by(predicate, xs) == minimum(xs, predicate)
0068     //!     minimum.by(predicate) == minimum(-, predicate)
0069     //! @endcode
0070     //!
0071     //! where `minimum(-, predicate)` denotes the partial application of
0072     //! `minimum` to `predicate`.
0073     //!
0074     //! ### Example
0075     //! @include example/minimum_by.cpp
0076     //!
0077     //!
0078     //! Tag dispatching
0079     //! ---------------
0080     //! Both the non-predicated version and the predicated versions of
0081     //! `minimum` are tag-dispatched methods, and hence they can be
0082     //! customized independently. One reason for this is that some
0083     //! structures are able to provide a much more efficient implementation
0084     //! of `minimum` when the `less` predicate is used. Here is how the
0085     //! different versions of `minimum` are dispatched:
0086     //! @code
0087     //!     minimum(xs) -> minimum_impl<tag of xs>::apply(xs)
0088     //!     minimum(xs, pred) -> minimum_pred_impl<tag of xs>::apply(xs, pred)
0089     //! @endcode
0090     //!
0091     //! Also note that `minimum.by` is not tag-dispatched on its own, since it
0092     //! is just syntactic sugar for calling the corresponding `minimum`.
0093 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0094     constexpr auto minimum = [](auto&& xs[, auto&& predicate]) -> decltype(auto) {
0095         return tag-dispatched;
0096     };
0097 #else
0098     template <typename T, typename = void>
0099     struct minimum_impl : minimum_impl<T, when<true>> { };
0100 
0101     template <typename T, typename = void>
0102     struct minimum_pred_impl : minimum_pred_impl<T, when<true>> { };
0103 
0104     struct minimum_t : detail::nested_by<minimum_t> {
0105         template <typename Xs>
0106         constexpr decltype(auto) operator()(Xs&& xs) const;
0107 
0108         template <typename Xs, typename Predicate>
0109         constexpr decltype(auto) operator()(Xs&& xs, Predicate&& pred) const;
0110     };
0111 
0112     BOOST_HANA_INLINE_VARIABLE constexpr minimum_t minimum{};
0113 #endif
0114 }} // end namespace boost::hana
0115 
0116 #endif // !BOOST_HANA_FWD_MINIMUM_HPP