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
23namespace 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 // cast bool to int to avoid -Wbitwise-instead-of-logical warning
42 return (0 != (static_cast<int>(f(*first1, *first2)) |
43 detail::any_ns(
44 fusion::next(first1)
45 , fusion::next(first2)
46 , last
47 , f
48 , fusion::result_of::equal_to<
49 typename fusion::result_of::next<First1>::type, Last>())));
50 }
51
52 template <typename First, typename Last, typename F>
53 inline bool
54 any_ns(First const&, Last const&, F const&, mpl::true_)
55 {
56 return false;
57 }
58
59 template <typename First, typename Last, typename F>
60 inline bool
61 any_ns(First const& first, Last const& last, F& f, mpl::false_)
62 {
63 // cast bool to int to avoid -Wbitwise-instead-of-logical warning
64 return (0 != (static_cast<int>(f(*first)) |
65 detail::any_ns(
66 fusion::next(first)
67 , last
68 , f
69 , fusion::result_of::equal_to<
70 typename fusion::result_of::next<First>::type, Last>())));
71 }
72 }
73
74 template <typename Sequence1, typename Sequence2, typename F>
75 inline bool
76 any_ns(Sequence1 const& seq1, Sequence2& seq2, F f)
77 {
78 return detail::any_ns(
79 fusion::begin(seq1)
80 , fusion::begin(seq2)
81 , fusion::end(seq1)
82 , f
83 , fusion::result_of::equal_to<
84 typename fusion::result_of::begin<Sequence1>::type
85 , typename fusion::result_of::end<Sequence1>::type>());
86 }
87
88 template <typename Sequence, typename F>
89 inline bool
90 any_ns(Sequence const& seq, unused_type, F f)
91 {
92 return detail::any_ns(
93 fusion::begin(seq)
94 , fusion::end(seq)
95 , f
96 , fusion::result_of::equal_to<
97 typename fusion::result_of::begin<Sequence>::type
98 , typename fusion::result_of::end<Sequence>::type>());
99 }
100
101}}
102
103#endif
104
105

source code of boost/libs/spirit/include/boost/spirit/home/support/algorithm/any_ns.hpp