Ticket #3044: iter_fold_if.patch
File iter_fold_if.patch, 7.7 KB (added by , 13 years ago) |
---|
-
boost/mpl/equal.hpp
74 74 , first2_ 75 75 , next<> 76 76 , protect< aux::equal_pred<Predicate,last1_,last2_> > 77 , void_ 78 , always<false_> 77 , identity<> 79 78 > fold_; 80 79 81 80 typedef typename fold_::iterator iter1_; -
boost/mpl/aux_/iter_fold_if_impl.hpp
81 81 }; 82 82 }; 83 83 84 template< bool > 85 struct 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 98 template<> 99 struct 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 84 112 // agurt, 25/jun/02: MSVC 6.5 workaround, had to get rid of inheritance 85 113 // here and in 'iter_fold_if_backward_step', because sometimes it interfered 86 114 // with the "early template instantiation bug" in _really_ ugly ways … … 104 132 template< 105 133 typename Iterator 106 134 , typename State 135 , typename ForwardNotLast 107 136 , typename BackwardOp 108 , typename Predicate109 137 > 110 138 struct iter_fold_if_backward_step 111 139 { 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_; 116 143 117 144 typedef typename impl_::state state; 118 typedef typename impl_::iterator iterator;119 145 }; 120 146 121 147 … … 134 160 typedef iter_fold_if_backward_step< \ 135 161 typename BOOST_PP_CAT(forward_step,BOOST_PP_DEC(i))::iterator \ 136 162 , typename BOOST_PP_CAT(backward_step,i)::state \ 163 , typename BOOST_PP_CAT(forward_step,i)::not_last \ 137 164 , BackwardOp \ 138 , BackwardPredicate \139 165 > BOOST_PP_CAT(backward_step,BOOST_PP_DEC(i)); \ 140 166 /**/ 141 167 … … 159 185 , typename ForwardOp 160 186 , typename ForwardPredicate 161 187 , typename BackwardOp 162 , typename BackwardPredicate163 188 > 164 189 struct iter_fold_if_impl 165 190 { … … 179 204 , ForwardOp 180 205 , ForwardPredicate 181 206 , BackwardOp 182 , BackwardPredicate183 207 > 184 208 , iter_fold_if_null_step< 185 209 typename AUX_LAST_FORWARD_STEP::iterator -
boost/mpl/iter_fold_if.hpp
62 62 , typename BOOST_MPL_AUX_NA_PARAM(ForwardOp) 63 63 , typename BOOST_MPL_AUX_NA_PARAM(ForwardPredicate) 64 64 , typename BOOST_MPL_AUX_NA_PARAM(BackwardOp) 65 , typename BOOST_MPL_AUX_NA_PARAM(BackwardPredicate)66 65 > 67 66 struct iter_fold_if 68 67 { … … 70 69 typedef typename begin<Sequence>::type first_; 71 70 typedef typename end<Sequence>::type last_; 72 71 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_; 78 73 79 74 // cwpro8 doesn't like 'cut-off' type here (use typedef instead) 80 75 #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) … … 87 82 , State 88 83 , ForwardOp 89 84 , protect< aux::iter_fold_if_pred< ForwardPredicate,last_ > > 90 , BackwardOp 91 , backward_pred_ 85 , backward_op_ 92 86 > 93 87 #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) && !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600)) 94 88 { }; … … 104 98 > type; 105 99 106 100 BOOST_MPL_AUX_LAMBDA_SUPPORT( 107 6101 5 108 102 , iter_fold_if 109 , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp ,BackwardPredicate)103 , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp) 110 104 ) 111 105 }; 112 106 113 BOOST_MPL_AUX_NA_SPEC( 6, iter_fold_if)107 BOOST_MPL_AUX_NA_SPEC(5, iter_fold_if) 114 108 115 109 }} 116 110 -
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 29 MPL_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 35 MPL_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 43 MPL_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 51 MPL_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 60 MPL_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
49 49 compile is_placeholder.cpp ; 50 50 compile is_sequence.cpp ; 51 51 compile iterator_tags.cpp ; 52 compile iter_fold_if.cpp ; 52 53 compile joint_view.cpp ; 53 54 compile lambda.cpp ; 54 55 compile lambda_args.cpp ;