File indexing completed on 2025-01-18 09:38:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_MONADIC_COMPOSE_HPP
0011 #define BOOST_HANA_MONADIC_COMPOSE_HPP
0012
0013 #include <boost/hana/fwd/monadic_compose.hpp>
0014
0015 #include <boost/hana/chain.hpp>
0016 #include <boost/hana/concept/monad.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/functional/partial.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023 namespace detail {
0024 struct monadic_compose_helper {
0025 template <typename F, typename G, typename X>
0026 constexpr decltype(auto) operator()(F&& f, G&& g, X&& x) const {
0027 using M = typename hana::tag_of<decltype(g(x))>::type;
0028
0029 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0030 static_assert(hana::Monad<M>::value,
0031 "hana::monadic_compose(f, g) requires 'g' to return a monadic value");
0032 #endif
0033
0034 return hana::chain(static_cast<G&&>(g)(static_cast<X&&>(x)),
0035 static_cast<F&&>(f));
0036 }
0037 };
0038 }
0039
0040
0041 template <typename F, typename G>
0042 constexpr auto monadic_compose_t::operator()(F&& f, G&& g) const {
0043 return hana::partial(detail::monadic_compose_helper{},
0044 static_cast<F&&>(f),
0045 static_cast<G&&>(g)
0046 );
0047 }
0048
0049 }}
0050
0051 #endif