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::drop_while`.
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_DROP_WHILE_HPP
0011 #define BOOST_HANA_DROP_WHILE_HPP
0012 
0013 #include <boost/hana/fwd/drop_while.hpp>
0014 
0015 #include <boost/hana/concept/foldable.hpp>
0016 #include <boost/hana/concept/iterable.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/detail/first_unsatisfied_index.hpp>
0020 #include <boost/hana/drop_front.hpp>
0021 #include <boost/hana/eval_if.hpp>
0022 #include <boost/hana/front.hpp>
0023 #include <boost/hana/is_empty.hpp>
0024 #include <boost/hana/lazy.hpp>
0025 
0026 
0027 namespace boost { namespace hana {
0028     //! @cond
0029     template <typename Xs, typename Pred>
0030     constexpr auto drop_while_t::operator()(Xs&& xs, Pred&& pred) const {
0031         using It = typename hana::tag_of<Xs>::type;
0032         using DropWhile = BOOST_HANA_DISPATCH_IF(drop_while_impl<It>,
0033             hana::Iterable<It>::value
0034         );
0035 
0036     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0037         static_assert(hana::Iterable<It>::value,
0038         "hana::drop_while(xs, pred) requires 'xs' to be an Iterable");
0039     #endif
0040 
0041         return DropWhile::apply(static_cast<Xs&&>(xs), static_cast<Pred&&>(pred));
0042     }
0043     //! @endcond
0044 
0045     namespace iterable_detail {
0046         struct drop_while_helper {
0047             struct next {
0048                 template <typename Xs, typename Pred>
0049                 constexpr decltype(auto) operator()(Xs&& xs, Pred&& pred) const {
0050                     return hana::drop_while(
0051                         hana::drop_front(static_cast<Xs&&>(xs)),
0052                         static_cast<Pred&&>(pred)
0053                     );
0054                 }
0055             };
0056 
0057             template <typename Xs, typename Pred>
0058             constexpr decltype(auto) operator()(Xs&& xs, Pred&& pred) const {
0059                 return hana::eval_if(pred(hana::front(xs)),
0060                     hana::make_lazy(next{})(xs, pred),
0061                     hana::make_lazy(xs)
0062                 );
0063             }
0064         };
0065     }
0066 
0067     template <typename It, bool condition>
0068     struct drop_while_impl<It, when<condition>> : default_ {
0069         template <typename Xs, typename Pred>
0070         static constexpr auto apply(Xs&& xs, Pred&& pred) {
0071             return hana::eval_if(hana::is_empty(xs),
0072                 hana::make_lazy(xs),
0073                 hana::make_lazy(iterable_detail::drop_while_helper{})(
0074                                             xs, static_cast<Pred&&>(pred))
0075             );
0076         }
0077     };
0078 
0079     template <typename S>
0080     struct drop_while_impl<S, when<hana::Foldable<S>::value>> {
0081         template <typename Xs, typename Pred>
0082         static constexpr auto apply(Xs&& xs, Pred&&) {
0083             using FirstUnsatisfied = decltype(
0084                 hana::unpack(static_cast<Xs&&>(xs),
0085                              detail::first_unsatisfied_index<Pred&&>{})
0086             );
0087             return hana::drop_front(static_cast<Xs&&>(xs),
0088                                     FirstUnsatisfied{});
0089         }
0090     };
0091 }} // end namespace boost::hana
0092 
0093 #endif // !BOOST_HANA_DROP_WHILE_HPP