| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::ap`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_FWD_AP_HPP |
| 11 | #define BOOST_HANA_FWD_AP_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | #include <boost/hana/core/when.hpp> |
| 15 | |
| 16 | |
| 17 | namespace boost { namespace hana { |
| 18 | //! Lifted application. |
| 19 | //! @ingroup group-Applicative |
| 20 | //! |
| 21 | //! Specifically, `ap` applies a structure containing functions to a |
| 22 | //! structure containing values, and returns a new structure containing |
| 23 | //! values. The exact way in which the functions are applied to the values |
| 24 | //! depends on the `Applicative`. |
| 25 | //! |
| 26 | //! `ap` can be called with two arguments or more; the functions in the `f` |
| 27 | //! structure are curried and then applied to the values in each `x...` |
| 28 | //! structure using the binary form of `ap`. Note that this requires the |
| 29 | //! number of `x...` must match the arity of the functions in the `f` |
| 30 | //! structure. In other words, `ap(f, x1, ..., xN)` is equivalent to |
| 31 | //! @code |
| 32 | //! ((curry(f) ap x1) ap x2) ... ap xN |
| 33 | //! @endcode |
| 34 | //! where `x ap y` is just `ap(x, y)` written in infix notation to |
| 35 | //! emphasize the left associativity. |
| 36 | //! |
| 37 | //! |
| 38 | //! Signature |
| 39 | //! --------- |
| 40 | //! Given an Applicative `A`, the signature is |
| 41 | //! @f$ \mathtt{ap} : A(T_1 \times \cdots \times T_n \to U) |
| 42 | //! \times A(T_1) \times \cdots \times A(T_n) |
| 43 | //! \to A(U) @f$. |
| 44 | //! |
| 45 | //! @param f |
| 46 | //! A structure containing function(s). |
| 47 | //! |
| 48 | //! @param x... |
| 49 | //! Structure(s) containing value(s) and on which `f` is applied. The |
| 50 | //! number of structures must match the arity of the functions in the |
| 51 | //! `f` structure. |
| 52 | //! |
| 53 | //! |
| 54 | //! Example |
| 55 | //! ------- |
| 56 | //! @include example/ap.cpp |
| 57 | //! |
| 58 | //! @todo |
| 59 | //! Consider giving access to all the arguments to the tag-dispatched |
| 60 | //! implementation for performance purposes. |
| 61 | #ifdef BOOST_HANA_DOXYGEN_INVOKED |
| 62 | constexpr auto ap = [](auto&& f, auto&& ...x) -> decltype(auto) { |
| 63 | return tag-dispatched; |
| 64 | }; |
| 65 | #else |
| 66 | template <typename A, typename = void> |
| 67 | struct ap_impl : ap_impl<A, when<true>> { }; |
| 68 | |
| 69 | struct ap_t { |
| 70 | template <typename F, typename X> |
| 71 | constexpr decltype(auto) operator()(F&& f, X&& x) const; |
| 72 | |
| 73 | template <typename F, typename ...Xs> |
| 74 | constexpr decltype(auto) operator()(F&& f, Xs&& ...xs) const; |
| 75 | }; |
| 76 | |
| 77 | BOOST_HANA_INLINE_VARIABLE constexpr ap_t ap{}; |
| 78 | #endif |
| 79 | }} // end namespace boost::hana |
| 80 | |
| 81 | #endif // !BOOST_HANA_FWD_AP_HPP |
| 82 | |