/*! @file Defines `boost::hana::unfold_right`. Copyright Louis Dionne 2013-2022 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_UNFOLD_RIGHT_HPP #define BOOST_HANA_UNFOLD_RIGHT_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template struct unfold_right_t { #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Sequence::value, "hana::unfold_right requires 'S' to be a Sequence"); #endif template constexpr auto operator()(State&& state, F&& f) const { return unfold_right_impl::apply( static_cast(state), static_cast(f) ); } }; //! @endcond template struct unfold_right_impl> : default_ { struct unfold_right_helper { template constexpr auto operator()(F&& f, P&& p) const { return hana::prepend( unfold_right_impl::apply( hana::second(static_cast(p)), static_cast(f) ), hana::first(static_cast(p)) ); } }; template static constexpr auto apply(Init&& init, F&& f) { decltype(auto) elt = f(static_cast(init)); return hana::maybe(hana::empty(), hana::partial(unfold_right_helper{}, static_cast(f)), static_cast(elt) ); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_UNFOLD_RIGHT_HPP