1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005 Eric Niebler
4 Copyright (c) 2007 Dan Marsden
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
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>
22 namespace boost { namespace fusion {
23 struct random_access_traversal_tag;
26 template <typename First, typename Last, typename F>
27 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
29 linear_any(First const&, Last const&, F const&, mpl::true_)
34 template <typename First, typename Last, typename F>
35 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
37 linear_any(First const& first, Last const& last, F& f, mpl::false_)
39 typename result_of::deref<First>::type x = *first;
45 , result_of::equal_to<typename result_of::next<First>::type, Last>());
48 template <typename Sequence, typename F, typename Tag>
49 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
51 any(Sequence const& seq, F f, Tag)
53 return detail::linear_any(
57 , result_of::equal_to<
58 typename result_of::begin<Sequence>::type
59 , typename result_of::end<Sequence>::type>());
65 template <typename It, typename F>
66 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
67 static bool call(It const& it, F f)
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);
79 struct unrolled_any<3>
81 template <typename It, typename F>
82 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
83 static bool call(It const& it, F f)
87 f(*fusion::advance_c<1>(it)) ||
88 f(*fusion::advance_c<2>(it));
93 struct unrolled_any<2>
95 template <typename It, typename F>
96 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
97 static bool call(It const& it, F f)
101 f(*fusion::advance_c<1>(it));
106 struct unrolled_any<1>
108 template <typename It, typename F>
109 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
110 static bool call(It const& it, F f)
117 struct unrolled_any<0>
119 template <typename It, typename F>
120 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
121 static bool call(It const&, F)
127 template <typename Sequence, typename F>
128 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
130 any(Sequence const& seq, F f, random_access_traversal_tag)
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);