]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
3 | ||
4 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ==============================================================================*/ | |
7 | #if !defined(BOOST_SPIRIT_ANY_NS_MARCH_13_2007_0827AM) | |
8 | #define BOOST_SPIRIT_ANY_NS_MARCH_13_2007_0827AM | |
9 | ||
10 | #if defined(_MSC_VER) | |
11 | #pragma once | |
12 | #endif | |
13 | ||
14 | #include <boost/mpl/bool.hpp> | |
15 | #include <boost/fusion/include/equal_to.hpp> | |
16 | #include <boost/fusion/include/next.hpp> | |
17 | #include <boost/fusion/include/deref.hpp> | |
18 | #include <boost/fusion/include/begin.hpp> | |
19 | #include <boost/fusion/include/end.hpp> | |
20 | #include <boost/fusion/include/any.hpp> | |
21 | #include <boost/spirit/home/support/unused.hpp> | |
22 | ||
23 | namespace boost { namespace spirit | |
24 | { | |
25 | // A non-short circuiting (ns) version of the any algorithm (uses | |
26 | // | instead of ||. | |
27 | ||
28 | namespace detail | |
29 | { | |
30 | template <typename First1, typename Last, typename First2, typename F> | |
31 | inline bool | |
32 | any_ns(First1 const&, First2 const&, Last const&, F const&, mpl::true_) | |
33 | { | |
34 | return false; | |
35 | } | |
36 | ||
37 | template <typename First1, typename Last, typename First2, typename F> | |
38 | inline bool | |
39 | any_ns(First1 const& first1, First2 const& first2, Last const& last, F& f, mpl::false_) | |
40 | { | |
41 | return (0 != (f(*first1, *first2) | | |
42 | detail::any_ns( | |
43 | fusion::next(first1) | |
44 | , fusion::next(first2) | |
45 | , last | |
46 | , f | |
47 | , fusion::result_of::equal_to< | |
48 | typename fusion::result_of::next<First1>::type, Last>()))); | |
49 | } | |
50 | ||
51 | template <typename First, typename Last, typename F> | |
52 | inline bool | |
53 | any_ns(First const&, Last const&, F const&, mpl::true_) | |
54 | { | |
55 | return false; | |
56 | } | |
57 | ||
58 | template <typename First, typename Last, typename F> | |
59 | inline bool | |
60 | any_ns(First const& first, Last const& last, F& f, mpl::false_) | |
61 | { | |
62 | return (0 != (f(*first) | | |
63 | detail::any_ns( | |
64 | fusion::next(first) | |
65 | , last | |
66 | , f | |
67 | , fusion::result_of::equal_to< | |
68 | typename fusion::result_of::next<First>::type, Last>()))); | |
69 | } | |
70 | } | |
71 | ||
72 | template <typename Sequence1, typename Sequence2, typename F> | |
73 | inline bool | |
74 | any_ns(Sequence1 const& seq1, Sequence2& seq2, F f) | |
75 | { | |
76 | return detail::any_ns( | |
77 | fusion::begin(seq1) | |
78 | , fusion::begin(seq2) | |
79 | , fusion::end(seq1) | |
80 | , f | |
81 | , fusion::result_of::equal_to< | |
82 | typename fusion::result_of::begin<Sequence1>::type | |
83 | , typename fusion::result_of::end<Sequence1>::type>()); | |
84 | } | |
85 | ||
86 | template <typename Sequence, typename F> | |
87 | inline bool | |
88 | any_ns(Sequence const& seq, unused_type, F f) | |
89 | { | |
90 | return detail::any_ns( | |
91 | fusion::begin(seq) | |
92 | , fusion::end(seq) | |
93 | , f | |
94 | , fusion::result_of::equal_to< | |
95 | typename fusion::result_of::begin<Sequence>::type | |
96 | , typename fusion::result_of::end<Sequence>::type>()); | |
97 | } | |
98 | ||
99 | }} | |
100 | ||
101 | #endif | |
102 |