Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:02

0001 /*!
0002 @file
0003 Defines `boost::hana::fold_right`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FOLD_RIGHT_HPP
0011 #define BOOST_HANA_FOLD_RIGHT_HPP
0012 
0013 #include <boost/hana/fwd/fold_right.hpp>
0014 
0015 #include <boost/hana/concept/foldable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/detail/variadic/foldr1.hpp>
0019 #include <boost/hana/functional/partial.hpp>
0020 #include <boost/hana/fwd/unpack.hpp>
0021 
0022 
0023 namespace boost { namespace hana {
0024     //! @cond
0025     template <typename Xs, typename State, typename F>
0026     constexpr decltype(auto) fold_right_t::operator()(Xs&& xs, State&& state, F&& f) const {
0027         using S = typename hana::tag_of<Xs>::type;
0028         using FoldRight = BOOST_HANA_DISPATCH_IF(fold_right_impl<S>,
0029             hana::Foldable<S>::value
0030         );
0031 
0032     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0033         static_assert(hana::Foldable<S>::value,
0034         "hana::fold_right(xs, state, f) requires 'xs' to be Foldable");
0035     #endif
0036 
0037         return FoldRight::apply(static_cast<Xs&&>(xs),
0038                                 static_cast<State&&>(state),
0039                                 static_cast<F&&>(f));
0040     }
0041 
0042     template <typename Xs, typename F>
0043     constexpr decltype(auto) fold_right_t::operator()(Xs&& xs, F&& f) const {
0044         using S = typename hana::tag_of<Xs>::type;
0045         using FoldRight = BOOST_HANA_DISPATCH_IF(fold_right_impl<S>,
0046             hana::Foldable<S>::value
0047         );
0048 
0049     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0050         static_assert(hana::Foldable<S>::value,
0051         "hana::fold_right(xs, f) requires 'xs' to be Foldable");
0052     #endif
0053 
0054         return FoldRight::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f));
0055     }
0056     //! @endcond
0057 
0058     namespace detail {
0059         template <typename F, typename State>
0060         struct variadic_foldr {
0061             F& f;
0062             State& state;
0063             template <typename ...T>
0064             constexpr decltype(auto) operator()(T&& ...t) const {
0065                 return detail::variadic::foldr(
0066                     static_cast<F&&>(f),
0067                     static_cast<State&&>(state),
0068                     static_cast<T&&>(t)...
0069                 );
0070             }
0071         };
0072     }
0073 
0074     template <typename T, bool condition>
0075     struct fold_right_impl<T, when<condition>> : default_ {
0076         // with state
0077         template <typename Xs, typename S, typename F>
0078         static constexpr decltype(auto) apply(Xs&& xs, S&& s, F&& f) {
0079             return hana::unpack(static_cast<Xs&&>(xs),
0080                 detail::variadic_foldr<F, S>{f, s}
0081             );
0082         }
0083 
0084         // without state
0085         template <typename Xs, typename F>
0086         static constexpr decltype(auto) apply(Xs&& xs, F&& f) {
0087             return hana::unpack(static_cast<Xs&&>(xs),
0088                 hana::partial(
0089                     detail::variadic::foldr1,
0090                     static_cast<F&&>(f)
0091                 )
0092             );
0093         }
0094     };
0095 }} // end namespace boost::hana
0096 
0097 #endif // !BOOST_HANA_FOLD_RIGHT_HPP