Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:40

0001 /*!
0002 @file
0003 Defines `boost::hana::unfold_left`.
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_UNFOLD_LEFT_HPP
0011 #define BOOST_HANA_UNFOLD_LEFT_HPP
0012 
0013 #include <boost/hana/fwd/unfold_left.hpp>
0014 
0015 #include <boost/hana/append.hpp>
0016 #include <boost/hana/concept/sequence.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/empty.hpp>
0020 #include <boost/hana/first.hpp>
0021 #include <boost/hana/functional/partial.hpp>
0022 #include <boost/hana/optional.hpp>
0023 #include <boost/hana/second.hpp>
0024 
0025 
0026 namespace boost { namespace hana {
0027     //! @cond
0028     template <typename S>
0029     struct unfold_left_t {
0030     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0031         static_assert(hana::Sequence<S>::value,
0032         "hana::unfold_left<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_left_impl<S>::apply(
0038                 static_cast<State&&>(state),
0039                 static_cast<F&&>(f)
0040             );
0041         }
0042     };
0043     //! @endcond
0044 
0045     template <typename S, bool condition>
0046     struct unfold_left_impl<S, when<condition>> : default_ {
0047         struct unfold_left_helper {
0048             template <typename F, typename P>
0049             constexpr auto operator()(F&& f, P&& p) const {
0050                 return hana::append(
0051                     unfold_left_impl::apply(
0052                         hana::first(static_cast<P&&>(p)),
0053                         static_cast<F&&>(f)
0054                     ),
0055                     hana::second(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(empty<S>(),
0064                 hana::partial(unfold_left_helper{}, static_cast<F&&>(f)),
0065                 static_cast<decltype(elt)&&>(elt)
0066             );
0067         }
0068     };
0069 }} // end namespace boost::hana
0070 
0071 #endif // !BOOST_HANA_UNFOLD_LEFT_HPP