• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3     Copyright (c) 2001-2011 Joel de Guzman
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #if !defined(BOOST_SPIRIT_ANY_IF_NS_SO_DECEMBER_03_2017_0826PM)
9 #define BOOST_SPIRIT_ANY_IF_NS_SO_DECEMBER_03_2017_0826PM
10 
11 #if defined(_MSC_VER)
12 #pragma once
13 #endif
14 
15 #include <boost/spirit/home/support/algorithm/any_ns_so.hpp>
16 
17 namespace boost { namespace spirit
18 {
19     ///////////////////////////////////////////////////////////////////////////
20     //  This is a special version for a binary fusion::any. The predicate
21     //  is used to decide whether to advance the second iterator or not.
22     //  This is needed for sequences containing components with unused
23     //  attributes. The second iterator is advanced only if the attribute
24     //  of the corresponding component iterator is not unused.
25     //
26     //  This is a non-short circuiting (ns) strict order (so) version of the
27     //  any_if algorithm.
28     ///////////////////////////////////////////////////////////////////////////
29     namespace detail
30     {
31         template <
32             typename Pred, typename First1, typename Last1, typename First2
33           , typename Last2, typename F
34         >
35         inline bool
any_if_ns_so(First1 const &,First2 const &,Last1 const &,Last2 const &,F const &,mpl::true_)36         any_if_ns_so(First1 const&, First2 const&, Last1 const&, Last2 const&
37           , F const&, mpl::true_)
38         {
39             return false;
40         }
41 
42         template <
43             typename Pred, typename First1, typename Last1, typename First2
44           , typename Last2, typename F
45         >
46         inline bool
any_if_ns_so(First1 const & first1,First2 const & first2,Last1 const & last1,Last2 const & last2,F & f,mpl::false_)47         any_if_ns_so(First1 const& first1, First2 const& first2
48           , Last1 const& last1, Last2 const& last2, F& f, mpl::false_)
49         {
50             typename result_of::attribute_value<First1, First2, Last2, Pred>::type
51                 attribute = spirit::detail::attribute_value<Pred, First1, Last2>(first2);
52 
53             bool head = f(*first1, attribute);
54             bool tail =
55                 detail::any_if_ns_so<Pred>(
56                     fusion::next(first1)
57                   , attribute_next<Pred, First1, Last2>(first2)
58                   , last1, last2
59                   , f
60                   , fusion::result_of::equal_to<
61                         typename fusion::result_of::next<First1>::type, Last1>());
62             return head || tail;
63         }
64     }
65 
66     template <typename Pred, typename Sequence1, typename Sequence2, typename F>
67     inline bool
any_if_ns_so(Sequence1 const & seq1,Sequence2 & seq2,F f,Pred)68     any_if_ns_so(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
69     {
70         return detail::any_if_ns_so<Pred>(
71                 fusion::begin(seq1), fusion::begin(seq2)
72               , fusion::end(seq1), fusion::end(seq2)
73               , f
74               , fusion::result_of::equal_to<
75                     typename fusion::result_of::begin<Sequence1>::type
76                   , typename fusion::result_of::end<Sequence1>::type>());
77     }
78 
79     template <typename Pred, typename Sequence, typename F>
80     inline bool
any_if_ns_so(Sequence const & seq,unused_type const,F f,Pred)81     any_if_ns_so(Sequence const& seq, unused_type const, F f, Pred)
82     {
83         return detail::any_ns_so(
84                 fusion::begin(seq)
85               , fusion::end(seq)
86               , f
87               , fusion::result_of::equal_to<
88                     typename fusion::result_of::begin<Sequence>::type
89                   , typename fusion::result_of::end<Sequence>::type>());
90     }
91 
92 }}
93 
94 #endif
95 
96