1 /////////////////////////////////////////////////////////////////////////////// 2 // any.hpp 3 // 4 // Copyright 2008 Eric Niebler. Distributed under the Boost 5 // Software License, Version 1.0. (See accompanying file 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 #ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_ANY_HPP_EAN_11_19_2005 9 #define BOOST_XPRESSIVE_DETAIL_UTILITY_ANY_HPP_EAN_11_19_2005 10 11 #include <boost/version.hpp> 12 13 #if BOOST_VERSION >= 103300 14 15 // In Boost 1.33+, we have a cons list in Fusion, so just include it. 16 17 # if BOOST_VERSION >= 103500 18 # include <boost/fusion/include/any.hpp> // Boost 1.35+ has Fusion2 19 # else 20 # include <boost/spirit/fusion/algorithm/any.hpp> // Fusion1 21 # endif 22 23 #else 24 25 # include <boost/spirit/fusion/sequence/begin.hpp> 26 # include <boost/spirit/fusion/sequence/end.hpp> 27 # include <boost/spirit/fusion/iterator/equal_to.hpp> 28 # include <boost/mpl/bool.hpp> 29 # include <boost/spirit/fusion/iterator/equal_to.hpp> 30 # include <boost/spirit/fusion/iterator/next.hpp> 31 # include <boost/spirit/fusion/iterator/deref.hpp> 32 33 namespace boost { namespace fusion 34 { 35 36 namespace detail 37 { 38 template <typename First, typename Last, typename F> 39 inline bool any(First const &,Last const &,F const &,mpl::true_)40 any(First const&, Last const&, F const&, mpl::true_) 41 { 42 return false; 43 } 44 45 template <typename First, typename Last, typename F> 46 inline bool any(First const & first,Last const & last,F const & f,mpl::false_)47 any(First const& first, Last const& last, F const& f, mpl::false_) 48 { 49 if(f(*first)) 50 return true; 51 return detail::any(fusion::next(first), last, f 52 , meta::equal_to<BOOST_DEDUCED_TYPENAME meta::next<First>::type, Last>()); 53 } 54 } 55 56 namespace meta 57 { 58 template <typename Sequence, typename F> 59 struct any 60 { 61 typedef bool type; 62 }; 63 } 64 65 namespace function 66 { 67 struct any 68 { 69 template <typename Sequence, typename F> 70 struct apply 71 { 72 typedef bool type; 73 }; 74 75 template <typename Sequence, typename F> 76 inline bool operator ()boost::fusion::function::any77 operator()(Sequence const& seq, F const& f) const 78 { 79 return detail::any( 80 fusion::begin(seq) 81 , fusion::end(seq) 82 , f 83 , meta::equal_to< 84 BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type 85 , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type>()); 86 } 87 88 template <typename Sequence, typename F> 89 inline bool operator ()boost::fusion::function::any90 operator()(Sequence& seq, F const& f) const 91 { 92 return detail::any( 93 fusion::begin(seq) 94 , fusion::end(seq) 95 , f 96 , meta::equal_to< 97 BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type 98 , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type>()); 99 } 100 }; 101 } 102 103 function::any const any = function::any(); 104 }} 105 106 #endif 107 108 #endif 109