Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:31:09

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003     Copyright (c) 2005 Eric Niebler
0004     Copyright (c) 2007 Dan Marsden
0005 
0006     Distributed under the Boost Software License, Version 1.0. (See accompanying 
0007     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 ==============================================================================*/
0009 #if !defined(FUSION_ANY_05052005_1229)
0010 #define FUSION_ANY_05052005_1229
0011 
0012 #include <boost/fusion/support/config.hpp>
0013 #include <boost/mpl/bool.hpp>
0014 #include <boost/fusion/sequence/intrinsic/begin.hpp>
0015 #include <boost/fusion/sequence/intrinsic/end.hpp>
0016 #include <boost/fusion/iterator/advance.hpp>
0017 #include <boost/fusion/iterator/equal_to.hpp>
0018 #include <boost/fusion/iterator/next.hpp>
0019 #include <boost/fusion/iterator/deref.hpp>
0020 #include <boost/fusion/iterator/distance.hpp>
0021 
0022 namespace boost { namespace fusion { 
0023     struct random_access_traversal_tag;
0024 namespace detail
0025 {
0026     template <typename First, typename Last, typename F>
0027     BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0028     inline bool
0029     linear_any(First const&, Last const&, F const&, mpl::true_)
0030     {
0031         return false;
0032     }
0033 
0034     template <typename First, typename Last, typename F>
0035     BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0036     inline bool
0037     linear_any(First const& first, Last const& last, F& f, mpl::false_)
0038     {
0039         typename result_of::deref<First>::type x = *first;
0040         return f(x) ||
0041             detail::linear_any(
0042                 fusion::next(first)
0043               , last
0044               , f
0045               , result_of::equal_to<typename result_of::next<First>::type, Last>());
0046     }
0047 
0048     template <typename Sequence, typename F, typename Tag>
0049     BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0050     inline bool
0051     any(Sequence const& seq, F f, Tag)
0052     {
0053         return detail::linear_any(
0054                 fusion::begin(seq)
0055               , fusion::end(seq)
0056               , f
0057               , result_of::equal_to<
0058                     typename result_of::begin<Sequence>::type
0059                   , typename result_of::end<Sequence>::type>());
0060     }
0061 
0062     template<int N>
0063     struct unrolled_any
0064     {
0065         template <typename It, typename F>
0066         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0067         static bool call(It const& it, F f)
0068         {
0069             return
0070                 f(*it) ||
0071                 f(*fusion::advance_c<1>(it))||
0072                 f(*fusion::advance_c<2>(it)) ||
0073                 f(*fusion::advance_c<3>(it)) ||
0074                 detail::unrolled_any<N-4>::call(fusion::advance_c<4>(it), f);
0075         }
0076     };
0077 
0078     template<>
0079     struct unrolled_any<3>
0080     {
0081         template <typename It, typename F>
0082         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0083         static bool call(It const& it, F f)
0084         {
0085             return
0086                 f(*it) ||
0087                 f(*fusion::advance_c<1>(it)) ||
0088                 f(*fusion::advance_c<2>(it));
0089         }
0090     };
0091 
0092     template<>
0093     struct unrolled_any<2>
0094     {
0095         template <typename It, typename F>
0096         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0097         static bool call(It const& it, F f)
0098         {
0099             return
0100                 f(*it) ||
0101                 f(*fusion::advance_c<1>(it));
0102         }
0103     };
0104 
0105     template<>
0106     struct unrolled_any<1>
0107     {
0108         template <typename It, typename F>
0109         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0110         static bool call(It const& it, F f)
0111         {
0112             return f(*it);
0113         }
0114     };
0115 
0116     template<>
0117     struct unrolled_any<0>
0118     {
0119         template <typename It, typename F>
0120         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0121         static bool call(It const&, F)
0122         {
0123             return false;
0124         }
0125     };
0126 
0127     template <typename Sequence, typename F>
0128     BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0129     inline bool
0130     any(Sequence const& seq, F f, random_access_traversal_tag)
0131     {
0132         typedef typename result_of::begin<Sequence>::type begin;
0133         typedef typename result_of::end<Sequence>::type end;
0134         return detail::unrolled_any<result_of::distance<begin, end>::type::value>::call(
0135             fusion::begin(seq), f);
0136     }
0137 }}}
0138 
0139 #endif
0140