123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #ifndef BOOST_HANA_FUNCTIONAL_COMPOSE_HPP
- #define BOOST_HANA_FUNCTIONAL_COMPOSE_HPP
- #include <boost/hana/config.hpp>
- #include <boost/hana/detail/create.hpp>
- #include <boost/hana/detail/variadic/foldl1.hpp>
- #include <utility>
- BOOST_HANA_NAMESPACE_BEGIN
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ifdef BOOST_HANA_DOXYGEN_INVOKED
- constexpr auto compose = [](auto&& f1, auto&& f2, ..., auto&& fn) {
- return [perfect-capture](auto&& x, auto&& ...xs) -> decltype(auto) {
- return forwarded(f1)(
- forwarded(f2)(
- ...
- forwarded(fn)(forwarded(x))
- ),
- forwarded(xs)...
- );
- }
- };
- #else
- template <typename F, typename G>
- struct _compose {
- F f; G g;
- template <typename X, typename ...Xs>
- constexpr decltype(auto) operator()(X&& x, Xs&& ...xs) const& {
- return f(
- g(static_cast<X&&>(x)),
- static_cast<Xs&&>(xs)...
- );
- }
- template <typename X, typename ...Xs>
- constexpr decltype(auto) operator()(X&& x, Xs&& ...xs) & {
- return f(
- g(static_cast<X&&>(x)),
- static_cast<Xs&&>(xs)...
- );
- }
- template <typename X, typename ...Xs>
- constexpr decltype(auto) operator()(X&& x, Xs&& ...xs) && {
- return std::move(f)(
- std::move(g)(static_cast<X&&>(x)),
- static_cast<Xs&&>(xs)...
- );
- }
- };
- struct _make_compose {
- template <typename F, typename G, typename ...H>
- constexpr decltype(auto) operator()(F&& f, G&& g, H&& ...h) const {
- return detail::variadic::foldl1(detail::create<_compose>{},
- static_cast<F&&>(f),
- static_cast<G&&>(g),
- static_cast<H&&>(h)...
- );
- }
- };
- constexpr _make_compose compose{};
- #endif
- BOOST_HANA_NAMESPACE_END
- #endif
|