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

source code of include/boost/fusion/algorithm/query/detail/any.hpp