3 Defines `boost::hana::monadic_compose`.
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)
10 #ifndef BOOST_HANA_MONADIC_COMPOSE_HPP
11 #define BOOST_HANA_MONADIC_COMPOSE_HPP
13 #include <boost/hana/fwd/monadic_compose.hpp>
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>
22 BOOST_HANA_NAMESPACE_BEGIN
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;
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");
34 return hana::chain(static_cast<G&&>(g)(static_cast<X&&>(x)),
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{},
49 BOOST_HANA_NAMESPACE_END
51 #endif // !BOOST_HANA_MONADIC_COMPOSE_HPP