/*! @file Defines `boost::hana::fold_right`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_FOLD_RIGHT_HPP #define BOOST_HANA_FOLD_RIGHT_HPP #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr decltype(auto) fold_right_t::operator()(Xs&& xs, State&& state, F&& f) const { using S = typename hana::tag_of::type; using FoldRight = BOOST_HANA_DISPATCH_IF(fold_right_impl, hana::Foldable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Foldable::value, "hana::fold_right(xs, state, f) requires 'xs' to be Foldable"); #endif return FoldRight::apply(static_cast(xs), static_cast(state), static_cast(f)); } template constexpr decltype(auto) fold_right_t::operator()(Xs&& xs, F&& f) const { using S = typename hana::tag_of::type; using FoldRight = BOOST_HANA_DISPATCH_IF(fold_right_impl, hana::Foldable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Foldable::value, "hana::fold_right(xs, f) requires 'xs' to be Foldable"); #endif return FoldRight::apply(static_cast(xs), static_cast(f)); } //! @endcond namespace detail { template struct variadic_foldr { F& f; State& state; template constexpr decltype(auto) operator()(T&& ...t) const { return detail::variadic::foldr( static_cast(f), static_cast(state), static_cast(t)... ); } }; } template struct fold_right_impl> : default_ { // with state template static constexpr decltype(auto) apply(Xs&& xs, S&& s, F&& f) { return hana::unpack(static_cast(xs), detail::variadic_foldr{f, s} ); } // without state template static constexpr decltype(auto) apply(Xs&& xs, F&& f) { return hana::unpack(static_cast(xs), hana::partial( detail::variadic::foldr1, static_cast(f) ) ); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_FOLD_RIGHT_HPP