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