Ticket #3044: iter_fold_if.patch

File iter_fold_if.patch, 7.7 KB (added by Steven Watanabe, 13 years ago)
  • boost/mpl/equal.hpp

     
    7474        , first2_
    7575        , next<>
    7676        , protect< aux::equal_pred<Predicate,last1_,last2_> >
    77         , void_
    78         , always<false_>
     77        , identity<>
    7978        > fold_;
    8079
    8180    typedef typename fold_::iterator iter1_;
  • boost/mpl/aux_/iter_fold_if_impl.hpp

     
    8181    };
    8282};
    8383
     84template< bool >
     85struct iter_fold_if_backward_step_impl
     86{
     87    template<
     88          typename Iterator
     89        , typename State
     90        , typename StateOp
     91        >
     92    struct result_
     93    {
     94        typedef typename apply2<StateOp,State,Iterator>::type state;
     95    };
     96};
     97
     98template<>
     99struct iter_fold_if_backward_step_impl<false>
     100{
     101    template<
     102          typename Iterator
     103        , typename State
     104        , typename StateOp
     105        >
     106    struct result_
     107    {
     108        typedef State state;
     109    };
     110};
     111
    84112// agurt, 25/jun/02: MSVC 6.5 workaround, had to get rid of inheritance
    85113// here and in 'iter_fold_if_backward_step', because sometimes it interfered
    86114// with the "early template instantiation bug" in _really_ ugly ways
     
    104132template<
    105133      typename Iterator
    106134    , typename State
     135    , typename ForwardNotLast
    107136    , typename BackwardOp
    108     , typename Predicate
    109137    >
    110138struct iter_fold_if_backward_step
    111139{
    112     typedef typename apply2<Predicate,State,Iterator>::type not_last;
    113     typedef typename iter_fold_if_step_impl<
    114           BOOST_MPL_AUX_MSVC_VALUE_WKND(not_last)::value
    115         >::template result_< Iterator,State,BackwardOp,identity<Iterator> > impl_;
     140    typedef typename iter_fold_if_backward_step_impl<
     141          BOOST_MPL_AUX_MSVC_VALUE_WKND(ForwardNotLast)::value
     142        >::template result_< Iterator,State,BackwardOp> impl_;
    116143
    117144    typedef typename impl_::state state;
    118     typedef typename impl_::iterator iterator;
    119145};
    120146
    121147
     
    134160    typedef iter_fold_if_backward_step< \
    135161          typename BOOST_PP_CAT(forward_step,BOOST_PP_DEC(i))::iterator \
    136162        , typename BOOST_PP_CAT(backward_step,i)::state \
     163        , typename BOOST_PP_CAT(forward_step,i)::not_last \
    137164        , BackwardOp \
    138         , BackwardPredicate \
    139165        > BOOST_PP_CAT(backward_step,BOOST_PP_DEC(i)); \
    140166    /**/
    141167
     
    159185    , typename ForwardOp
    160186    , typename ForwardPredicate
    161187    , typename BackwardOp
    162     , typename BackwardPredicate
    163188    >
    164189struct iter_fold_if_impl
    165190{
     
    179204            , ForwardOp
    180205            , ForwardPredicate
    181206            , BackwardOp
    182             , BackwardPredicate
    183207            >
    184208        , iter_fold_if_null_step<
    185209              typename AUX_LAST_FORWARD_STEP::iterator
  • boost/mpl/iter_fold_if.hpp

     
    6262    , typename BOOST_MPL_AUX_NA_PARAM(ForwardOp)
    6363    , typename BOOST_MPL_AUX_NA_PARAM(ForwardPredicate)
    6464    , typename BOOST_MPL_AUX_NA_PARAM(BackwardOp)
    65     , typename BOOST_MPL_AUX_NA_PARAM(BackwardPredicate)
    6665    >
    6766struct iter_fold_if
    6867{
     
    7069    typedef typename begin<Sequence>::type first_;
    7170    typedef typename end<Sequence>::type last_;
    7271
    73     typedef typename eval_if<
    74           is_na<BackwardPredicate>
    75         , if_< is_na<BackwardOp>, always<false_>, always<true_> >
    76         , identity<BackwardPredicate>
    77         >::type backward_pred_;
     72    typedef typename if_< is_na<BackwardOp>, identity<>, BackwardOp >::type backward_op_;
    7873
    7974// cwpro8 doesn't like 'cut-off' type here (use typedef instead)
    8075#if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
     
    8782        , State
    8883        , ForwardOp
    8984        , protect< aux::iter_fold_if_pred< ForwardPredicate,last_ > >
    90         , BackwardOp
    91         , backward_pred_
     85        , backward_op_
    9286        >
    9387#if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
    9488    { };
     
    10498        > type;
    10599
    106100    BOOST_MPL_AUX_LAMBDA_SUPPORT(
    107           6
     101          5
    108102        , iter_fold_if
    109         , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate)
     103        , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp)
    110104        )
    111105};
    112106
    113 BOOST_MPL_AUX_NA_SPEC(6, iter_fold_if)
     107BOOST_MPL_AUX_NA_SPEC(5, iter_fold_if)
    114108
    115109}}
    116110
  • libs/mpl/test/iter_fold_if.cpp

     
     1
     2// Copyright Steven Watanabe 2009
     3//
     4// Distributed under the Boost Software License, Version 1.0.
     5// (See accompanying file LICENSE_1_0.txt or copy at
     6// http://www.boost.org/LICENSE_1_0.txt)
     7//
     8// See http://www.boost.org/libs/mpl for documentation.
     9
     10// $Id$
     11// $Date: $
     12// $Revision: $
     13
     14#include <boost/mpl/iter_fold_if.hpp>
     15
     16#include <boost/mpl/list.hpp>
     17#include <boost/mpl/list_c.hpp>
     18#include <boost/mpl/end.hpp>
     19#include <boost/mpl/advance.hpp>
     20#include <boost/mpl/always.hpp>
     21#include <boost/mpl/equal_to.hpp>
     22#include <boost/mpl/not_equal_to.hpp>
     23#include <boost/mpl/plus.hpp>
     24#include <boost/mpl/bool.hpp>
     25#include <boost/mpl/int.hpp>
     26
     27#include <boost/mpl/aux_/test.hpp>
     28
     29MPL_TEST_CASE()
     30{
     31    typedef iter_fold_if<list<>, void, deref<_2>, always<true_>, deref<_2> >::type result;
     32    MPL_ASSERT((is_same<result::first, void>));
     33}
     34
     35MPL_TEST_CASE() // test forward fold functionality
     36{
     37    typedef list<char, short, int, long, float, double> types;
     38    typedef iter_fold_if<types, void, deref<_2>, always<true_> >::type result;
     39    MPL_ASSERT((is_same<result::first, double>));
     40    MPL_ASSERT((is_same<result::second, end<types>::type>));
     41}
     42
     43MPL_TEST_CASE() // test reverse fold functionality
     44{
     45    typedef list<char, short, int, long, float, double> types;
     46    typedef iter_fold_if<types, void, deref<_2>, always<true_>, deref<_2> >::type result;
     47    MPL_ASSERT((is_same<result::first, char>));
     48    MPL_ASSERT((is_same<result::second, end<types>::type>));
     49}
     50
     51MPL_TEST_CASE() // test forward condition
     52{
     53    typedef list_c<int, 1, 2, 4, 8, 16> numbers;
     54    typedef iter_fold_if<numbers, int_<0>, plus<_1, deref<_2> >, not_equal_to<deref<_1>, int_<8> > >::type result;
     55    MPL_ASSERT((equal_to<result::first, int_<7> >));
     56    MPL_ASSERT((is_same<result::second, advance_c<begin<numbers>::type, 3>::type>));
     57}
     58
     59
     60MPL_TEST_CASE() // test backwards condition
     61{
     62    typedef list_c<int, 1, 2, 4, 8, 16> numbers;
     63    typedef iter_fold_if<
     64        numbers
     65      , int_<0>
     66      , identity<_1>
     67      , not_equal_to<deref<_1>, int_<8> >
     68      , plus<_1, deref<_2> >
     69      >::type result;
     70    MPL_ASSERT((equal_to<result::first, int_<7> >));
     71    MPL_ASSERT((is_same<result::second, advance_c<begin<numbers>::type, 3>::type>));
     72}
  • libs/mpl/test/Jamfile.v2

    Property changes on: libs\mpl\test\iter_fold_if.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
    4949compile is_placeholder.cpp ;
    5050compile is_sequence.cpp ;
    5151compile iterator_tags.cpp ;
     52compile iter_fold_if.cpp ;
    5253compile joint_view.cpp ;
    5354compile lambda.cpp ;
    5455compile lambda_args.cpp ;