3 Defines `boost::hana::take_while`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_TAKE_WHILE_HPP
11 #define BOOST_HANA_TAKE_WHILE_HPP
13 #include <boost/hana/fwd/take_while.hpp>
15 #include <boost/hana/concept/sequence.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
18 #include <boost/hana/detail/first_unsatisfied_index.hpp>
19 #include <boost/hana/take_front.hpp>
20 #include <boost/hana/unpack.hpp>
23 BOOST_HANA_NAMESPACE_BEGIN
25 template <typename Xs, typename Pred>
26 constexpr auto take_while_t::operator()(Xs&& xs, Pred&& pred) const {
27 using S = typename hana::tag_of<Xs>::type;
28 using TakeWhile = BOOST_HANA_DISPATCH_IF(take_while_impl<S>,
29 hana::Sequence<S>::value
32 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
33 static_assert(hana::Sequence<S>::value,
34 "hana::take_while(xs, pred) requires 'xs' to be a Sequence");
37 return TakeWhile::apply(static_cast<Xs&&>(xs),
38 static_cast<Pred&&>(pred));
42 template <typename S, bool condition>
43 struct take_while_impl<S, when<condition>> : default_ {
44 template <typename Xs, typename Pred>
45 static constexpr auto apply(Xs&& xs, Pred&&) {
46 using FirstUnsatisfied = decltype(
47 hana::unpack(static_cast<Xs&&>(xs),
48 detail::first_unsatisfied_index<Pred&&>{})
50 return hana::take_front(static_cast<Xs&&>(xs), FirstUnsatisfied{});
53 BOOST_HANA_NAMESPACE_END
55 #endif // !BOOST_HANA_TAKE_WHILE_HPP