]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/include/boost/fusion/algorithm/query/detail/segmented_find_if.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / include / boost / fusion / algorithm / query / detail / segmented_find_if.hpp
1 /*=============================================================================
2 Copyright (c) 2011 Eric Niebler
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(BOOST_FUSION_SEGMENTED_FIND_IF_HPP_INCLUDED)
8 #define BOOST_FUSION_SEGMENTED_FIND_IF_HPP_INCLUDED
9
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/mpl/eval_if.hpp>
12 #include <boost/mpl/identity.hpp>
13 #include <boost/fusion/algorithm/query/find_if_fwd.hpp>
14 #include <boost/fusion/iterator/equal_to.hpp>
15 #include <boost/fusion/sequence/intrinsic/end.hpp>
16 #include <boost/fusion/support/segmented_fold_until.hpp>
17
18 namespace boost { namespace fusion { namespace detail
19 {
20 template <typename Pred>
21 struct segmented_find_if_fun
22 {
23 template <typename Sequence, typename State, typename Context>
24 struct apply
25 {
26 typedef
27 typename result_of::find_if<Sequence, Pred>::type
28 iterator_type;
29
30 typedef
31 typename result_of::equal_to<
32 iterator_type
33 , typename result_of::end<Sequence>::type
34 >::type
35 continue_type;
36
37 typedef
38 typename mpl::eval_if<
39 continue_type
40 , mpl::identity<State>
41 , result_of::make_segmented_iterator<
42 iterator_type
43 , Context
44 >
45 >::type
46 type;
47
48 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
49 static type call(Sequence& seq, State const&state, Context const& context, segmented_find_if_fun)
50 {
51 return call_impl(seq, state, context, continue_type());
52 }
53
54 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
55 static type call_impl(Sequence&, State const&state, Context const&, mpl::true_)
56 {
57 return state;
58 }
59
60 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
61 static type call_impl(Sequence& seq, State const&, Context const& context, mpl::false_)
62 {
63 return fusion::make_segmented_iterator(fusion::find_if<Pred>(seq), context);
64 }
65 };
66 };
67
68 template <typename Sequence, typename Pred>
69 struct result_of_segmented_find_if
70 {
71 struct filter
72 {
73 typedef
74 typename result_of::segmented_fold_until<
75 Sequence
76 , typename result_of::end<Sequence>::type
77 , segmented_find_if_fun<Pred>
78 >::type
79 type;
80
81 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
82 static type call(Sequence& seq)
83 {
84 return fusion::segmented_fold_until(
85 seq
86 , fusion::end(seq)
87 , segmented_find_if_fun<Pred>());
88 }
89 };
90
91 typedef typename filter::type type;
92 };
93 }}}
94
95 #endif