/usr/include/boost/spirit/home/support/algorithm
Edit: /usr/include/boost/spirit/home/support/algorithm/any_if.hpp (7683B)
/*=============================================================================
Copyright (c) 2001-2011 Hartmut Kaiser
Copyright (c) 2001-2011 Joel de Guzman
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_SPIRIT_ANY_IF_MARCH_30_2007_1220PM)
#define BOOST_SPIRIT_ANY_IF_MARCH_30_2007_1220PM
#if defined(_MSC_VER)
#pragma once
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost { namespace spirit
{
///////////////////////////////////////////////////////////////////////////
// This is a special version for a binary fusion::any. The predicate
// is used to decide whether to advance the second iterator or not.
// This is needed for sequences containing components with unused
// attributes. The second iterator is advanced only if the attribute
// of the corresponding component iterator is not unused.
///////////////////////////////////////////////////////////////////////////
namespace detail
{
///////////////////////////////////////////////////////////////////////
template
struct apply_predicate
: mpl::apply1::type>
{};
///////////////////////////////////////////////////////////////////////
// if the predicate is true, attribute_next returns next(Iterator2),
// otherwise Iterator2
namespace result_of
{
template <
typename Iterator1, typename Iterator2, typename Last2
, typename Pred>
struct attribute_next
{
typedef mpl::and_<
apply_predicate
, mpl::not_ >
> pred;
typedef typename
mpl::eval_if<
pred
, fusion::result_of::next
, mpl::identity
>::type
type;
template
static type
call(Iterator const& i, mpl::true_)
{
return fusion::next(i);
}
template
static type
call(Iterator const& i, mpl::false_)
{
return i;
}
template
static type
call(Iterator const& i)
{
return call(i, pred());
}
};
}
template <
typename Pred, typename Iterator1, typename Last2
, typename Iterator2>
inline typename
result_of::attribute_next::type const
attribute_next(Iterator2 const& i)
{
return result_of::attribute_next<
Iterator1, Iterator2, Last2, Pred>::call(i);
}
///////////////////////////////////////////////////////////////////////
// if the predicate is true, attribute_value returns deref(Iterator2),
// otherwise unused
namespace result_of
{
template <
typename Iterator1, typename Iterator2, typename Last2
, typename Pred>
struct attribute_value
{
typedef mpl::and_<
apply_predicate
, mpl::not_ >
> pred;
typedef typename
mpl::eval_if<
pred
, fusion::result_of::deref
, mpl::identity
>::type
type;
template
static type
call(Iterator const& i, mpl::true_)
{
return fusion::deref(i);
}
template
static type
call(Iterator const&, mpl::false_)
{
return unused;
}
template
static type
call(Iterator const& i)
{
return call(i, pred());
}
};
}
template <
typename Pred, typename Iterator1, typename Last2
, typename Iterator2>
inline typename
result_of::attribute_value::type
attribute_value(Iterator2 const& i)
{
return result_of::attribute_value<
Iterator1, Iterator2, Last2, Pred>::call(i);
}
///////////////////////////////////////////////////////////////////////
template <
typename Pred, typename First1, typename Last1, typename First2
, typename Last2, typename F>
inline bool
any_if (First1 const&, First2 const&, Last1 const&, Last2 const&
, F const&, mpl::true_)
{
return false;
}
template <
typename Pred, typename First1, typename Last1, typename First2
, typename Last2, typename F>
inline bool
any_if (First1 const& first1, First2 const& first2, Last1 const& last1
, Last2 const& last2, F& f, mpl::false_)
{
typename result_of::attribute_value::type
attribute = spirit::detail::attribute_value(first2);
return f(*first1, attribute) ||
detail::any_if(
fusion::next(first1)
, attribute_next(first2)
, last1, last2
, f
, fusion::result_of::equal_to<
typename fusion::result_of::next::type, Last1>());
}
}
template
inline bool
any_if(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
{
return detail::any_if(
fusion::begin(seq1), fusion::begin(seq2)
, fusion::end(seq1), fusion::end(seq2)
, f
, fusion::result_of::equal_to<
typename fusion::result_of::begin::type
, typename fusion::result_of::end::type>());
}
template
inline bool
any_if(Sequence const& seq, unused_type const, F f, Pred)
{
return fusion::any(seq, f);
}
}}
#endif