1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2007 Dan Marsden
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(FUSION_ALL_05052005_1237)
9 #define FUSION_ALL_05052005_1237
11 #include <boost/fusion/support/config.hpp>
12 #include <boost/mpl/bool.hpp>
13 #include <boost/fusion/sequence/intrinsic/begin.hpp>
14 #include <boost/fusion/sequence/intrinsic/end.hpp>
15 #include <boost/fusion/iterator/advance.hpp>
16 #include <boost/fusion/iterator/equal_to.hpp>
17 #include <boost/fusion/iterator/next.hpp>
18 #include <boost/fusion/iterator/deref.hpp>
19 #include <boost/fusion/iterator/distance.hpp>
21 namespace boost { namespace fusion { namespace detail
23 template <typename First, typename Last, typename F>
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
26 linear_all(First const&, Last const&, F const&, mpl::true_)
31 template <typename First, typename Last, typename F>
32 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
34 linear_all(First const& first, Last const& last, F& f, mpl::false_)
36 typename result_of::deref<First>::type x = *first;
42 , result_of::equal_to<typename result_of::next<First>::type, Last>());
45 template <typename Sequence, typename F, typename Tag>
46 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
48 all(Sequence const& seq, F f, Tag)
50 return detail::linear_all(
54 , result_of::equal_to<
55 typename result_of::begin<Sequence>::type
56 , typename result_of::end<Sequence>::type>());
62 template <typename It, typename F>
63 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
64 static bool call(It const& it, F f)
68 f(*fusion::advance_c<1>(it))&&
69 f(*fusion::advance_c<2>(it)) &&
70 f(*fusion::advance_c<3>(it)) &&
71 detail::unrolled_all<N-4>::call(fusion::advance_c<4>(it), f);
76 struct unrolled_all<3>
78 template <typename It, typename F>
79 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
80 static bool call(It const& it, F f)
84 f(*fusion::advance_c<1>(it)) &&
85 f(*fusion::advance_c<2>(it));
90 struct unrolled_all<2>
92 template <typename It, typename F>
93 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
94 static bool call(It const& it, F f)
98 f(*fusion::advance_c<1>(it));
103 struct unrolled_all<1>
105 template <typename It, typename F>
106 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
107 static bool call(It const& it, F f)
114 struct unrolled_all<0>
116 template <typename It, typename F>
117 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
118 static bool call(It const& /*it*/, F /*f*/)
124 template <typename Sequence, typename F>
125 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
127 all(Sequence const& seq, F f, random_access_traversal_tag)
129 typedef typename result_of::begin<Sequence>::type begin;
130 typedef typename result_of::end<Sequence>::type end;
131 return detail::unrolled_all<result_of::distance<begin, end>::type::value>::call(
132 fusion::begin(seq), f);