123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /*!
- @file
- Forward declares `boost::hana::ap`.
- @copyright Louis Dionne 2013-2017
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
- */
- #ifndef BOOST_HANA_FWD_AP_HPP
- #define BOOST_HANA_FWD_AP_HPP
- #include <boost/hana/config.hpp>
- #include <boost/hana/core/when.hpp>
- BOOST_HANA_NAMESPACE_BEGIN
- //! Lifted application.
- //! @ingroup group-Applicative
- //!
- //! Specifically, `ap` applies a structure containing functions to a
- //! structure containing values, and returns a new structure containing
- //! values. The exact way in which the functions are applied to the values
- //! depends on the `Applicative`.
- //!
- //! `ap` can be called with two arguments or more; the functions in the `f`
- //! structure are curried and then applied to the values in each `x...`
- //! structure using the binary form of `ap`. Note that this requires the
- //! number of `x...` must match the arity of the functions in the `f`
- //! structure. In other words, `ap(f, x1, ..., xN)` is equivalent to
- //! @code
- //! ((curry(f) ap x1) ap x2) ... ap xN
- //! @endcode
- //! where `x ap y` is just `ap(x, y)` written in infix notation to
- //! emphasize the left associativity.
- //!
- //!
- //! Signature
- //! ---------
- //! Given an Applicative `A`, the signature is
- //! @f$ \mathtt{ap} : A(T_1 \times \cdots \times T_n \to U)
- //! \times A(T_1) \times \cdots \times A(T_n)
- //! \to A(U) @f$.
- //!
- //! @param f
- //! A structure containing function(s).
- //!
- //! @param x...
- //! Structure(s) containing value(s) and on which `f` is applied. The
- //! number of structures must match the arity of the functions in the
- //! `f` structure.
- //!
- //!
- //! Example
- //! -------
- //! @include example/ap.cpp
- //!
- //! @todo
- //! Consider giving access to all the arguments to the tag-dispatched
- //! implementation for performance purposes.
- #ifdef BOOST_HANA_DOXYGEN_INVOKED
- constexpr auto ap = [](auto&& f, auto&& ...x) -> decltype(auto) {
- return tag-dispatched;
- };
- #else
- template <typename A, typename = void>
- struct ap_impl : ap_impl<A, when<true>> { };
- struct ap_t {
- template <typename F, typename X>
- constexpr decltype(auto) operator()(F&& f, X&& x) const;
- template <typename F, typename ...Xs>
- constexpr decltype(auto) operator()(F&& f, Xs&& ...xs) const;
- };
- constexpr ap_t ap{};
- #endif
- BOOST_HANA_NAMESPACE_END
- #endif // !BOOST_HANA_FWD_AP_HPP
|