Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59353 - trunk/boost/spirit/home/support/algorithm
From: hartmut.kaiser_at_[hidden]
Date: 2010-01-29 21:12:39


Author: hkaiser
Date: 2010-01-29 21:12:38 EST (Fri, 29 Jan 2010)
New Revision: 59353
URL: http://svn.boost.org/trac/boost/changeset/59353

Log:
Spirit: fixing sequences with unused attribute at the end
Text files modified:
   trunk/boost/spirit/home/support/algorithm/any_if.hpp | 82 ++++++++++++++++++++++++---------------
   trunk/boost/spirit/home/support/algorithm/any_if_ns.hpp | 28 ++++++------
   2 files changed, 64 insertions(+), 46 deletions(-)

Modified: trunk/boost/spirit/home/support/algorithm/any_if.hpp
==============================================================================
--- trunk/boost/spirit/home/support/algorithm/any_if.hpp (original)
+++ trunk/boost/spirit/home/support/algorithm/any_if.hpp 2010-01-29 21:12:38 EST (Fri, 29 Jan 2010)
@@ -26,6 +26,8 @@
 #include <boost/mpl/apply.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/identity.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/not.hpp>
 
 namespace boost { namespace spirit
 {
@@ -49,15 +51,21 @@
         // otherwise Iterator2
         namespace result_of
         {
- template <typename Iterator1, typename Iterator2, typename Pred>
+ template <
+ typename Iterator1, typename Iterator2, typename Last2
+ , typename Pred>
             struct attribute_next
             {
- typedef typename apply_predicate<Iterator1, Pred>::type pred;
+ typedef mpl::and_<
+ apply_predicate<Iterator1, Pred>
+ , mpl::not_<fusion::result_of::equal_to<Iterator2, Last2> >
+ > pred;
+
                 typedef typename
                     mpl::eval_if<
- pred,
- fusion::result_of::next<Iterator2>,
- mpl::identity<Iterator2>
+ pred
+ , fusion::result_of::next<Iterator2>
+ , mpl::identity<Iterator2>
>::type
                 type;
 
@@ -84,13 +92,16 @@
             };
         }
 
- template <typename Pred, typename Iterator1, typename Iterator2>
+ template <
+ typename Pred, typename Iterator1, typename Last2
+ , typename Iterator2>
         inline typename
- result_of::attribute_next<Iterator1, Iterator2, Pred
+ result_of::attribute_next<Iterator1, Iterator2, Last2, Pred
>::type const
         attribute_next(Iterator2 const& i)
         {
- return result_of::attribute_next<Iterator1, Iterator2, Pred>::call(i);
+ return result_of::attribute_next<
+ Iterator1, Iterator2, Last2, Pred>::call(i);
         }
 
         ///////////////////////////////////////////////////////////////////////
@@ -98,15 +109,21 @@
         // otherwise unused
         namespace result_of
         {
- template <typename Iterator1, typename Iterator2, typename Pred>
+ template <
+ typename Iterator1, typename Iterator2, typename Last2
+ , typename Pred>
             struct attribute_value
             {
- typedef typename apply_predicate<Iterator1, Pred>::type pred;
+ typedef mpl::and_<
+ apply_predicate<Iterator1, Pred>
+ , mpl::not_<fusion::result_of::equal_to<Iterator2, Last2> >
+ > pred;
+
                 typedef typename
                     mpl::eval_if<
- pred,
- fusion::result_of::deref<Iterator2>,
- mpl::identity<unused_type const>
+ pred
+ , fusion::result_of::deref<Iterator2>
+ , mpl::identity<unused_type const>
>::type
                 type;
 
@@ -133,42 +150,44 @@
             };
         }
 
- template <typename Pred, typename Iterator1, typename Iterator2>
+ template <
+ typename Pred, typename Iterator1, typename Last2
+ , typename Iterator2>
         inline typename
- result_of::attribute_value<Iterator1, Iterator2, Pred
+ result_of::attribute_value<Iterator1, Iterator2, Last2, Pred
>::type
         attribute_value(Iterator2 const& i)
         {
- return result_of::attribute_value<Iterator1, Iterator2, Pred>::call(i);
+ return result_of::attribute_value<
+ Iterator1, Iterator2, Last2, Pred>::call(i);
         }
 
         ///////////////////////////////////////////////////////////////////////
         template <
- typename Pred, typename First1, typename Last, typename First2,
- typename F
- >
+ typename Pred, typename First1, typename Last1, typename First2
+ , typename Last2, typename F>
         inline bool
- any_if (First1 const&, First2 const&, Last const&, F const&, mpl::true_)
+ any_if (First1 const&, First2 const&, Last1 const&, Last2 const&
+ , F const&, mpl::true_)
         {
             return false;
         }
 
         template <
- typename Pred, typename First1, typename Last, typename First2,
- typename F
- >
+ typename Pred, typename First1, typename Last1, typename First2
+ , typename Last2, typename F>
         inline bool
- any_if (First1 const& first1, First2 const& first2, Last const& last,
- F& f, mpl::false_)
+ any_if (First1 const& first1, First2 const& first2, Last1 const& last1
+ , Last2 const& last2, F& f, mpl::false_)
         {
- return f(*first1, attribute_value<Pred, First1>(first2)) ||
+ return f(*first1, attribute_value<Pred, First1, Last2>(first2)) ||
                 detail::any_if<Pred>(
                     fusion::next(first1)
- , attribute_next<Pred, First1>(first2)
- , last
+ , attribute_next<Pred, First1, Last2>(first2)
+ , last1, last2
                   , f
                   , fusion::result_of::equal_to<
- typename fusion::result_of::next<First1>::type, Last>());
+ typename fusion::result_of::next<First1>::type, Last1>());
         }
     }
 
@@ -177,9 +196,8 @@
     any_if(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
     {
         return detail::any_if<Pred>(
- fusion::begin(seq1)
- , fusion::begin(seq2)
- , fusion::end(seq1)
+ fusion::begin(seq1), fusion::begin(seq2)
+ , fusion::end(seq1), fusion::end(seq2)
               , f
               , fusion::result_of::equal_to<
                     typename fusion::result_of::begin<Sequence1>::type

Modified: trunk/boost/spirit/home/support/algorithm/any_if_ns.hpp
==============================================================================
--- trunk/boost/spirit/home/support/algorithm/any_if_ns.hpp (original)
+++ trunk/boost/spirit/home/support/algorithm/any_if_ns.hpp 2010-01-29 21:12:38 EST (Fri, 29 Jan 2010)
@@ -30,31 +30,32 @@
     namespace detail
     {
         template <
- typename Pred, typename First1, typename Last, typename First2,
- typename F
+ typename Pred, typename First1, typename Last1, typename First2
+ , typename Last2, typename F
>
         inline bool
- any_if_ns(First1 const&, First2 const&, Last const&, F const&, mpl::true_)
+ any_if_ns(First1 const&, First2 const&, Last1 const&, Last2 const&
+ , F const&, mpl::true_)
         {
             return false;
         }
 
         template <
- typename Pred, typename First1, typename Last, typename First2,
- typename F
+ typename Pred, typename First1, typename Last1, typename First2
+ , typename Last2, typename F
>
         inline bool
- any_if_ns(First1 const& first1, First2 const& first2, Last const& last,
- F& f, mpl::false_)
+ any_if_ns(First1 const& first1, First2 const& first2
+ , Last1 const& last1, Last2 const& last2, F& f, mpl::false_)
         {
- return (0 != (f(*first1, attribute_value<Pred, First1>(first2)) |
+ return (0 != (f(*first1, attribute_value<Pred, First1, Last2>(first2)) |
                 detail::any_if_ns<Pred>(
                     fusion::next(first1)
- , attribute_next<Pred, First1>(first2)
- , last
+ , attribute_next<Pred, First1, Last2>(first2)
+ , last1, last2
                   , f
                   , fusion::result_of::equal_to<
- typename fusion::result_of::next<First1>::type, Last>())));
+ typename fusion::result_of::next<First1>::type, Last1>())));
         }
     }
 
@@ -63,9 +64,8 @@
     any_if_ns(Sequence1 const& seq1, Sequence2& seq2, F f, Pred)
     {
         return detail::any_if_ns<Pred>(
- fusion::begin(seq1)
- , fusion::begin(seq2)
- , fusion::end(seq1)
+ fusion::begin(seq1), fusion::begin(seq2)
+ , fusion::end(seq1), fusion::end(seq2)
               , f
               , fusion::result_of::equal_to<
                     typename fusion::result_of::begin<Sequence1>::type


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk