Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2005 Eric Niebler
|
Chris@16
|
4 Copyright (c) 2007 Dan Marsden
|
Chris@16
|
5
|
Chris@16
|
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 ==============================================================================*/
|
Chris@16
|
9 #if !defined(FUSION_ANY_05052005_1229)
|
Chris@16
|
10 #define FUSION_ANY_05052005_1229
|
Chris@16
|
11
|
Chris@101
|
12 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
13 #include <boost/mpl/bool.hpp>
|
Chris@16
|
14 #include <boost/fusion/sequence/intrinsic/begin.hpp>
|
Chris@16
|
15 #include <boost/fusion/sequence/intrinsic/end.hpp>
|
Chris@16
|
16 #include <boost/fusion/iterator/advance.hpp>
|
Chris@16
|
17 #include <boost/fusion/iterator/equal_to.hpp>
|
Chris@16
|
18 #include <boost/fusion/iterator/next.hpp>
|
Chris@16
|
19 #include <boost/fusion/iterator/deref.hpp>
|
Chris@16
|
20 #include <boost/fusion/iterator/distance.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost { namespace fusion {
|
Chris@16
|
23 struct random_access_traversal_tag;
|
Chris@16
|
24 namespace detail
|
Chris@16
|
25 {
|
Chris@16
|
26 template <typename First, typename Last, typename F>
|
Chris@101
|
27 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
28 inline bool
|
Chris@16
|
29 linear_any(First const&, Last const&, F const&, mpl::true_)
|
Chris@16
|
30 {
|
Chris@16
|
31 return false;
|
Chris@16
|
32 }
|
Chris@16
|
33
|
Chris@16
|
34 template <typename First, typename Last, typename F>
|
Chris@101
|
35 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
36 inline bool
|
Chris@16
|
37 linear_any(First const& first, Last const& last, F& f, mpl::false_)
|
Chris@16
|
38 {
|
Chris@16
|
39 typename result_of::deref<First>::type x = *first;
|
Chris@101
|
40 return f(x) ||
|
Chris@16
|
41 detail::linear_any(
|
Chris@16
|
42 fusion::next(first)
|
Chris@16
|
43 , last
|
Chris@16
|
44 , f
|
Chris@16
|
45 , result_of::equal_to<typename result_of::next<First>::type, Last>());
|
Chris@16
|
46 }
|
Chris@16
|
47
|
Chris@16
|
48 template <typename Sequence, typename F, typename Tag>
|
Chris@101
|
49 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
50 inline bool
|
Chris@16
|
51 any(Sequence const& seq, F f, Tag)
|
Chris@16
|
52 {
|
Chris@16
|
53 return detail::linear_any(
|
Chris@16
|
54 fusion::begin(seq)
|
Chris@16
|
55 , fusion::end(seq)
|
Chris@16
|
56 , f
|
Chris@16
|
57 , result_of::equal_to<
|
Chris@16
|
58 typename result_of::begin<Sequence>::type
|
Chris@16
|
59 , typename result_of::end<Sequence>::type>());
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 template<int N>
|
Chris@16
|
63 struct unrolled_any
|
Chris@16
|
64 {
|
Chris@16
|
65 template <typename It, typename F>
|
Chris@101
|
66 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
67 static bool call(It const& it, F f)
|
Chris@16
|
68 {
|
Chris@101
|
69 return
|
Chris@101
|
70 f(*it) ||
|
Chris@16
|
71 f(*fusion::advance_c<1>(it))||
|
Chris@16
|
72 f(*fusion::advance_c<2>(it)) ||
|
Chris@16
|
73 f(*fusion::advance_c<3>(it)) ||
|
Chris@16
|
74 detail::unrolled_any<N-4>::call(fusion::advance_c<4>(it), f);
|
Chris@16
|
75 }
|
Chris@16
|
76 };
|
Chris@16
|
77
|
Chris@16
|
78 template<>
|
Chris@16
|
79 struct unrolled_any<3>
|
Chris@16
|
80 {
|
Chris@16
|
81 template <typename It, typename F>
|
Chris@101
|
82 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
83 static bool call(It const& it, F f)
|
Chris@16
|
84 {
|
Chris@101
|
85 return
|
Chris@101
|
86 f(*it) ||
|
Chris@16
|
87 f(*fusion::advance_c<1>(it)) ||
|
Chris@16
|
88 f(*fusion::advance_c<2>(it));
|
Chris@16
|
89 }
|
Chris@16
|
90 };
|
Chris@16
|
91
|
Chris@16
|
92 template<>
|
Chris@16
|
93 struct unrolled_any<2>
|
Chris@16
|
94 {
|
Chris@16
|
95 template <typename It, typename F>
|
Chris@101
|
96 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
97 static bool call(It const& it, F f)
|
Chris@16
|
98 {
|
Chris@101
|
99 return
|
Chris@101
|
100 f(*it) ||
|
Chris@16
|
101 f(*fusion::advance_c<1>(it));
|
Chris@16
|
102 }
|
Chris@16
|
103 };
|
Chris@16
|
104
|
Chris@16
|
105 template<>
|
Chris@16
|
106 struct unrolled_any<1>
|
Chris@16
|
107 {
|
Chris@16
|
108 template <typename It, typename F>
|
Chris@101
|
109 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
110 static bool call(It const& it, F f)
|
Chris@16
|
111 {
|
Chris@16
|
112 return f(*it);
|
Chris@16
|
113 }
|
Chris@16
|
114 };
|
Chris@16
|
115
|
Chris@16
|
116 template<>
|
Chris@16
|
117 struct unrolled_any<0>
|
Chris@16
|
118 {
|
Chris@16
|
119 template <typename It, typename F>
|
Chris@101
|
120 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
121 static bool call(It const&, F)
|
Chris@16
|
122 {
|
Chris@16
|
123 return false;
|
Chris@16
|
124 }
|
Chris@16
|
125 };
|
Chris@16
|
126
|
Chris@16
|
127 template <typename Sequence, typename F>
|
Chris@101
|
128 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
129 inline bool
|
Chris@16
|
130 any(Sequence const& seq, F f, random_access_traversal_tag)
|
Chris@16
|
131 {
|
Chris@16
|
132 typedef typename result_of::begin<Sequence>::type begin;
|
Chris@16
|
133 typedef typename result_of::end<Sequence>::type end;
|
Chris@16
|
134 return detail::unrolled_any<result_of::distance<begin, end>::type::value>::call(
|
Chris@16
|
135 fusion::begin(seq), f);
|
Chris@16
|
136 }
|
Chris@16
|
137 }}}
|
Chris@16
|
138
|
Chris@16
|
139 #endif
|
Chris@16
|
140
|