Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:47

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Hartmut Kaiser
0003     Copyright (c) 2001-2011 Joel de Guzman
0004 
0005     Distributed under the Boost Software License, Version 1.0. (See accompanying
0006     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 ==============================================================================*/
0008 #if !defined(BOOST_SPIRIT_ANY_IF_NS_NOVEMBER_04_2008_0906PM)
0009 #define BOOST_SPIRIT_ANY_IF_NS_NOVEMBER_04_2008_0906PM
0010 
0011 #if defined(_MSC_VER)
0012 #pragma once
0013 #endif
0014 
0015 #include <boost/spirit/home/support/algorithm/any_if.hpp>
0016 #include <boost/spirit/home/support/algorithm/any_ns.hpp>
0017 
0018 namespace boost { namespace spirit
0019 {
0020     ///////////////////////////////////////////////////////////////////////////
0021     //  This is a special version for a binary fusion::any. The predicate
0022     //  is used to decide whether to advance the second iterator or not.
0023     //  This is needed for sequences containing components with unused
0024     //  attributes. The second iterator is advanced only if the attribute
0025     //  of the corresponding component iterator is not unused.
0026     //
0027     //  This is a non-short circuiting (ns) version of the any_if algorithm.
0028     //  see any_if.hpp (uses | instead of ||).
0029     ///////////////////////////////////////////////////////////////////////////
0030     namespace detail
0031     {
0032         template <
0033             typename Pred, typename First1, typename Last1, typename First2
0034           , typename Last2, typename F
0035         >
0036         inline bool
0037         any_if_ns(First1 const&, First2 const&, Last1 const&, Last2 const&
0038           , F const&, mpl::true_)
0039         {
0040             return false;
0041         }
0042 
0043         template <
0044             typename Pred, typename First1, typename Last1, typename First2
0045           , typename Last2, typename F
0046         >
0047         inline bool
0048         any_if_ns(First1 const& first1, First2 const& first2
0049           , Last1 const& last1, Last2 const& last2, F& f, mpl::false_)
0050         {
0051             typename result_of::attribute_value<First1, First2, Last2, Pred>::type
0052                 attribute = spirit::detail::attribute_value<Pred, First1, Last2>(first2);
0053 
0054             // cast bool to int to avoid -Wbitwise-instead-of-logical warning
0055             return (0 != (static_cast<int>(f(*first1, attribute)) |
0056                 detail::any_if_ns<Pred>(
0057                     fusion::next(first1)
0058                   , attribute_next<Pred, First1, Last2>(first2)
0059                   , last1, last2
0060                   , f
0061                   , fusion::result_of::equal_to<
0062                         typename fusion::result_of::next<First1>::type, Last1>())));
0063         }
0064     }
0065 
0066     template <typename Pred, typename Sequence1, typename Sequence2, typename F>
0067     inline bool
0068     any_if_ns(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
0069     {
0070         return detail::any_if_ns<Pred>(
0071                 fusion::begin(seq1), fusion::begin(seq2)
0072               , fusion::end(seq1), fusion::end(seq2)
0073               , f
0074               , fusion::result_of::equal_to<
0075                     typename fusion::result_of::begin<Sequence1>::type
0076                   , typename fusion::result_of::end<Sequence1>::type>());
0077     }
0078 
0079     template <typename Pred, typename Sequence, typename F>
0080     inline bool
0081     any_if_ns(Sequence const& seq, unused_type const, F f, Pred)
0082     {
0083         return detail::any_ns(
0084                 fusion::begin(seq)
0085               , fusion::end(seq)
0086               , f
0087               , fusion::result_of::equal_to<
0088                     typename fusion::result_of::begin<Sequence>::type
0089                   , typename fusion::result_of::end<Sequence>::type>());
0090     }
0091 
0092 }}
0093 
0094 #endif
0095