]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/ap.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / ap.hpp
1 /*!
2 @file
3 Defines `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_AP_HPP
11 #define BOOST_HANA_AP_HPP
12
13 #include <boost/hana/fwd/ap.hpp>
14
15 #include <boost/hana/chain.hpp>
16 #include <boost/hana/concept/applicative.hpp>
17 #include <boost/hana/concept/sequence.hpp>
18 #include <boost/hana/config.hpp>
19 #include <boost/hana/core/dispatch.hpp>
20 #include <boost/hana/detail/variadic/foldl1.hpp>
21 #include <boost/hana/functional/curry.hpp>
22 #include <boost/hana/functional/partial.hpp>
23 #include <boost/hana/transform.hpp>
24
25
26 BOOST_HANA_NAMESPACE_BEGIN
27 template <typename A, bool condition>
28 struct ap_impl<A, when<condition>> : default_ {
29 template <typename ...Args>
30 static constexpr auto apply(Args&& ...args) = delete;
31 };
32
33 //! @cond
34 template <typename F, typename X>
35 constexpr decltype(auto) ap_t::operator()(F&& f, X&& x) const {
36 using Function = typename hana::tag_of<F>::type;
37 using Value = typename hana::tag_of<X>::type;
38 using Ap = BOOST_HANA_DISPATCH_IF(ap_impl<Function>,
39 hana::Applicative<Function>::value && hana::Applicative<Value>::value
40 );
41
42 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
43 static_assert(hana::Applicative<Function>::value,
44 "hana::ap(f, x) requires 'f' to be an Applicative");
45
46 static_assert(hana::Applicative<Value>::value,
47 "hana::ap(f, x) requires 'x' to be an Applicative");
48 #endif
49
50 return Ap::apply(static_cast<F&&>(f), static_cast<X&&>(x));
51 }
52
53 template <typename F, typename ...Xs>
54 constexpr decltype(auto) ap_t::operator()(F&& f, Xs&& ...xs) const {
55 static_assert(sizeof...(xs) >= 1,
56 "hana::ap must be called with at least two arguments");
57
58 return detail::variadic::foldl1(
59 *this,
60 hana::transform(static_cast<F&&>(f), hana::curry<sizeof...(xs)>),
61 static_cast<Xs&&>(xs)...
62 );
63 }
64 //! @endcond
65
66 template <typename S>
67 struct ap_impl<S, when<Sequence<S>::value>> {
68 template <typename F, typename X>
69 static constexpr decltype(auto) apply(F&& f, X&& x) {
70 return hana::chain(
71 static_cast<F&&>(f),
72 hana::partial(hana::transform, static_cast<X&&>(x))
73 );
74 }
75 };
76 BOOST_HANA_NAMESPACE_END
77
78 #endif // !BOOST_HANA_AP_HPP