/*! @file Defines `boost::hana::drop_while`. @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_DROP_WHILE_HPP #define BOOST_HANA_DROP_WHILE_HPP #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr auto drop_while_t::operator()(Xs&& xs, Pred&& pred) const { using It = typename hana::tag_of::type; using DropWhile = BOOST_HANA_DISPATCH_IF(drop_while_impl, hana::Iterable::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Iterable::value, "hana::drop_while(xs, pred) requires 'xs' to be an Iterable"); #endif return DropWhile::apply(static_cast(xs), static_cast(pred)); } //! @endcond namespace iterable_detail { struct drop_while_helper { struct next { template constexpr decltype(auto) operator()(Xs&& xs, Pred&& pred) const { return hana::drop_while( hana::drop_front(static_cast(xs)), static_cast(pred) ); } }; template constexpr decltype(auto) operator()(Xs&& xs, Pred&& pred) const { return hana::eval_if(pred(hana::front(xs)), hana::make_lazy(next{})(xs, pred), hana::make_lazy(xs) ); } }; } template struct drop_while_impl> : default_ { template static constexpr auto apply(Xs&& xs, Pred&& pred) { return hana::eval_if(hana::is_empty(xs), hana::make_lazy(xs), hana::make_lazy(iterable_detail::drop_while_helper{})( xs, static_cast(pred)) ); } }; template struct drop_while_impl::value>> { template static constexpr auto apply(Xs&& xs, Pred&&) { using FirstUnsatisfied = decltype( hana::unpack(static_cast(xs), detail::first_unsatisfied_index{}) ); return hana::drop_front(static_cast(xs), FirstUnsatisfied{}); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_DROP_WHILE_HPP