File indexing completed on 2025-01-30 09:43:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_UNFOLD_RIGHT_HPP
0011 #define BOOST_HANA_UNFOLD_RIGHT_HPP
0012
0013 #include <boost/hana/fwd/unfold_right.hpp>
0014
0015 #include <boost/hana/concept/sequence.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/empty.hpp>
0019 #include <boost/hana/first.hpp>
0020 #include <boost/hana/functional/partial.hpp>
0021 #include <boost/hana/optional.hpp>
0022 #include <boost/hana/prepend.hpp>
0023 #include <boost/hana/second.hpp>
0024
0025
0026 namespace boost { namespace hana {
0027
0028 template <typename S>
0029 struct unfold_right_t {
0030 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0031 static_assert(hana::Sequence<S>::value,
0032 "hana::unfold_right<S> requires 'S' to be a Sequence");
0033 #endif
0034
0035 template <typename State, typename F>
0036 constexpr auto operator()(State&& state, F&& f) const {
0037 return unfold_right_impl<S>::apply(
0038 static_cast<State&&>(state),
0039 static_cast<F&&>(f)
0040 );
0041 }
0042 };
0043
0044
0045 template <typename S, bool condition>
0046 struct unfold_right_impl<S, when<condition>> : default_ {
0047 struct unfold_right_helper {
0048 template <typename F, typename P>
0049 constexpr auto operator()(F&& f, P&& p) const {
0050 return hana::prepend(
0051 unfold_right_impl::apply(
0052 hana::second(static_cast<P&&>(p)),
0053 static_cast<F&&>(f)
0054 ),
0055 hana::first(static_cast<P&&>(p))
0056 );
0057 }
0058 };
0059
0060 template <typename Init, typename F>
0061 static constexpr auto apply(Init&& init, F&& f) {
0062 decltype(auto) elt = f(static_cast<Init&&>(init));
0063 return hana::maybe(hana::empty<S>(),
0064 hana::partial(unfold_right_helper{}, static_cast<F&&>(f)),
0065 static_cast<decltype(elt)&&>(elt)
0066 );
0067 }
0068 };
0069 }}
0070
0071 #endif