| 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_if.hpp> |
| 16 | #include <boost/spirit/home/support/algorithm/any_ns_so.hpp> |
| 17 | |
| 18 | namespace boost { namespace spirit |
| 19 | { |
| 20 | /////////////////////////////////////////////////////////////////////////// |
| 21 | // This is a special version for a binary fusion::any. The predicate |
| 22 | // is used to decide whether to advance the second iterator or not. |
| 23 | // This is needed for sequences containing components with unused |
| 24 | // attributes. The second iterator is advanced only if the attribute |
| 25 | // of the corresponding component iterator is not unused. |
| 26 | // |
| 27 | // This is a non-short circuiting (ns) strict order (so) version of the |
| 28 | // any_if algorithm. |
| 29 | /////////////////////////////////////////////////////////////////////////// |
| 30 | namespace detail |
| 31 | { |
| 32 | template < |
| 33 | typename Pred, typename First1, typename Last1, typename First2 |
| 34 | , typename Last2, typename F |
| 35 | > |
| 36 | inline bool |
| 37 | any_if_ns_so(First1 const&, First2 const&, Last1 const&, Last2 const& |
| 38 | , F const&, mpl::true_) |
| 39 | { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | template < |
| 44 | typename Pred, typename First1, typename Last1, typename First2 |
| 45 | , typename Last2, typename F |
| 46 | > |
| 47 | inline bool |
| 48 | any_if_ns_so(First1 const& first1, First2 const& first2 |
| 49 | , Last1 const& last1, Last2 const& last2, F& f, mpl::false_) |
| 50 | { |
| 51 | typename result_of::attribute_value<First1, First2, Last2, Pred>::type |
| 52 | attribute = spirit::detail::attribute_value<Pred, First1, Last2>(first2); |
| 53 | |
| 54 | bool head = f(*first1, attribute); |
| 55 | bool tail = |
| 56 | detail::any_if_ns_so<Pred>( |
| 57 | fusion::next(first1) |
| 58 | , attribute_next<Pred, First1, Last2>(first2) |
| 59 | , last1, last2 |
| 60 | , f |
| 61 | , fusion::result_of::equal_to< |
| 62 | typename fusion::result_of::next<First1>::type, Last1>()); |
| 63 | return head || tail; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | template <typename Pred, typename Sequence1, typename Sequence2, typename F> |
| 68 | inline bool |
| 69 | any_if_ns_so(Sequence1 const& seq1, Sequence2& seq2, F f, Pred) |
| 70 | { |
| 71 | return detail::any_if_ns_so<Pred>( |
| 72 | fusion::begin(seq1), fusion::begin(seq2) |
| 73 | , fusion::end(seq1), fusion::end(seq2) |
| 74 | , f |
| 75 | , fusion::result_of::equal_to< |
| 76 | typename fusion::result_of::begin<Sequence1>::type |
| 77 | , typename fusion::result_of::end<Sequence1>::type>()); |
| 78 | } |
| 79 | |
| 80 | template <typename Pred, typename Sequence, typename F> |
| 81 | inline bool |
| 82 | any_if_ns_so(Sequence const& seq, unused_type const, F f, Pred) |
| 83 | { |
| 84 | return detail::any_ns_so( |
| 85 | fusion::begin(seq) |
| 86 | , fusion::end(seq) |
| 87 | , f |
| 88 | , fusion::result_of::equal_to< |
| 89 | typename fusion::result_of::begin<Sequence>::type |
| 90 | , typename fusion::result_of::end<Sequence>::type>()); |
| 91 | } |
| 92 | |
| 93 | }} |
| 94 | |
| 95 | #endif |
| 96 | |
| 97 | |