]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::ap`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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 | BOOST_HANA_NAMESPACE_BEGIN | |
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 | //! ((f' <ap> x1) <ap> x2) ... <ap> xN | |
33 | //! @endcode | |
34 | //! where `f'` is `f` but containing curried functions instead and | |
35 | //! `x <ap> y` is just `ap(x, y)` written in infix notation to emphasize | |
36 | //! the left associativity. | |
37 | //! | |
38 | //! | |
39 | //! Signature | |
40 | //! --------- | |
41 | //! Given an Applicative `A`, the signature is | |
42 | //! @f$ \mathtt{ap} : A(T_1 \times \cdots \times T_n \to U) | |
43 | //! \times A(T_1) \times \cdots \times A(T_n) | |
44 | //! \to A(U) @f$. | |
45 | //! | |
46 | //! @param f | |
47 | //! A structure containing function(s). | |
48 | //! | |
49 | //! @param x... | |
50 | //! Structure(s) containing value(s) and on which `f` is applied. The | |
51 | //! number of structures must match the arity of the functions in the | |
52 | //! `f` structure. | |
53 | //! | |
54 | //! | |
55 | //! Example | |
56 | //! ------- | |
57 | //! @include example/ap.cpp | |
58 | //! | |
59 | //! @todo | |
60 | //! Consider giving access to all the arguments to the tag-dispatched | |
61 | //! implementation for performance purposes. | |
62 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
63 | constexpr auto ap = [](auto&& f, auto&& ...x) -> decltype(auto) { | |
64 | return tag-dispatched; | |
65 | }; | |
66 | #else | |
67 | template <typename A, typename = void> | |
68 | struct ap_impl : ap_impl<A, when<true>> { }; | |
69 | ||
70 | struct ap_t { | |
71 | template <typename F, typename X> | |
72 | constexpr decltype(auto) operator()(F&& f, X&& x) const; | |
73 | ||
74 | template <typename F, typename ...Xs> | |
75 | constexpr decltype(auto) operator()(F&& f, Xs&& ...xs) const; | |
76 | }; | |
77 | ||
78 | constexpr ap_t ap{}; | |
79 | #endif | |
80 | BOOST_HANA_NAMESPACE_END | |
81 | ||
82 | #endif // !BOOST_HANA_FWD_AP_HPP |