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