File indexing completed on 2025-01-18 09:38:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_TAKE_WHILE_HPP
0011 #define BOOST_HANA_TAKE_WHILE_HPP
0012
0013 #include <boost/hana/fwd/take_while.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/detail/first_unsatisfied_index.hpp>
0019 #include <boost/hana/take_front.hpp>
0020 #include <boost/hana/unpack.hpp>
0021
0022
0023 namespace boost { namespace hana {
0024
0025 template <typename Xs, typename Pred>
0026 constexpr auto take_while_t::operator()(Xs&& xs, Pred&& pred) const {
0027 using S = typename hana::tag_of<Xs>::type;
0028 using TakeWhile = BOOST_HANA_DISPATCH_IF(take_while_impl<S>,
0029 hana::Sequence<S>::value
0030 );
0031
0032 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0033 static_assert(hana::Sequence<S>::value,
0034 "hana::take_while(xs, pred) requires 'xs' to be a Sequence");
0035 #endif
0036
0037 return TakeWhile::apply(static_cast<Xs&&>(xs),
0038 static_cast<Pred&&>(pred));
0039 }
0040
0041
0042 template <typename S, bool condition>
0043 struct take_while_impl<S, when<condition>> : default_ {
0044 template <typename Xs, typename Pred>
0045 static constexpr auto apply(Xs&& xs, Pred&&) {
0046 using FirstUnsatisfied = decltype(
0047 hana::unpack(static_cast<Xs&&>(xs),
0048 detail::first_unsatisfied_index<Pred&&>{})
0049 );
0050 return hana::take_front(static_cast<Xs&&>(xs), FirstUnsatisfied{});
0051 }
0052 };
0053 }}
0054
0055 #endif