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