]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/monadic_compose.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / monadic_compose.hpp
1 /*!
2 @file
3 Defines `boost::hana::monadic_compose`.
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_MONADIC_COMPOSE_HPP
11 #define BOOST_HANA_MONADIC_COMPOSE_HPP
12
13 #include <boost/hana/fwd/monadic_compose.hpp>
14
15 #include <boost/hana/chain.hpp>
16 #include <boost/hana/concept/monad.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
19 #include <boost/hana/functional/partial.hpp>
20
21
22 BOOST_HANA_NAMESPACE_BEGIN
23 namespace detail {
24 struct monadic_compose_helper {
25 template <typename F, typename G, typename X>
26 constexpr decltype(auto) operator()(F&& f, G&& g, X&& x) const {
27 using M = typename hana::tag_of<decltype(g(x))>::type;
28
29 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
30 static_assert(hana::Monad<M>::value,
31 "hana::monadic_compose(f, g) requires 'g' to return a monadic value");
32 #endif
33
34 return hana::chain(static_cast<G&&>(g)(static_cast<X&&>(x)),
35 static_cast<F&&>(f));
36 }
37 };
38 }
39
40 //! @cond
41 template <typename F, typename G>
42 constexpr auto monadic_compose_t::operator()(F&& f, G&& g) const {
43 return hana::partial(detail::monadic_compose_helper{},
44 static_cast<F&&>(f),
45 static_cast<G&&>(g)
46 );
47 }
48 //! @endcond
49 BOOST_HANA_NAMESPACE_END
50
51 #endif // !BOOST_HANA_MONADIC_COMPOSE_HPP