]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/take_while.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / take_while.hpp
1 /*!
2 @file
3 Defines `boost::hana::take_while`.
4
5 @copyright Louis Dionne 2013-2016
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)
8 */
9
10 #ifndef BOOST_HANA_TAKE_WHILE_HPP
11 #define BOOST_HANA_TAKE_WHILE_HPP
12
13 #include <boost/hana/fwd/take_while.hpp>
14
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>
21
22
23 BOOST_HANA_NAMESPACE_BEGIN
24 //! @cond
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
30 );
31
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");
35 #endif
36
37 return TakeWhile::apply(static_cast<Xs&&>(xs),
38 static_cast<Pred&&>(pred));
39 }
40 //! @endcond
41
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&&>{})
49 );
50 return hana::take_front(static_cast<Xs&&>(xs), FirstUnsatisfied{});
51 }
52 };
53 BOOST_HANA_NAMESPACE_END
54
55 #endif // !BOOST_HANA_TAKE_WHILE_HPP