1/*!
2@file
3Defines `boost::hana::monadic_compose`.
4
5Copyright Louis Dionne 2013-2022
6Distributed 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
22namespace boost { namespace hana {
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}} // end namespace boost::hana
50
51#endif // !BOOST_HANA_MONADIC_COMPOSE_HPP
52

source code of boost/libs/hana/include/boost/hana/monadic_compose.hpp