diff --git a/include/boost/mpl/aux_/find_if_pred.hpp b/include/boost/mpl/aux_/find_if_pred.hpp index 4bf5348..ebac68c 100644 --- a/include/boost/mpl/aux_/find_if_pred.hpp +++ b/include/boost/mpl/aux_/find_if_pred.hpp @@ -4,7 +4,7 @@ //----------------------------------------------------------------------------- // // Copyright (c) 2000-02 -// Aleksey Gurtovoy +// Aleksey Gurtovoy, Eric Friedman // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, @@ -18,25 +18,19 @@ #define BOOST_MPL_AUX_FIND_IF_PRED_HPP_INCLUDED #include "boost/mpl/aux_/iter_apply.hpp" -#include "boost/mpl/apply.hpp" #include "boost/mpl/not.hpp" -#include "boost/mpl/or.hpp" -#include "boost/type_traits/is_same.hpp" namespace boost { namespace mpl { namespace aux { -template< typename Predicate, typename LastIterator > +template< typename Predicate > struct find_if_pred { - template< typename State, typename Iterator > + template< typename Iterator > struct apply { - typedef not_< or_< - is_same - , aux::iter_apply1 - > > type; + typedef not_< aux::iter_apply1 > type; }; }; diff --git a/include/boost/mpl/find_if.hpp b/include/boost/mpl/find_if.hpp index ea2fbae..3f3f5ca 100644 --- a/include/boost/mpl/find_if.hpp +++ b/include/boost/mpl/find_if.hpp @@ -18,36 +18,16 @@ #define BOOST_MPL_FIND_IF_HPP_INCLUDED #include "boost/mpl/aux_/find_if_pred.hpp" -#include "boost/mpl/aux_/iter_fold_if_impl.hpp" -#include "boost/mpl/begin_end.hpp" -#include "boost/mpl/always.hpp" +#include "boost/mpl/arg.hpp" #include "boost/mpl/lambda.hpp" +#include "boost/mpl/iter_fold_if.hpp" +#include "boost/mpl/protect.hpp" #include "boost/mpl/aux_/void_spec.hpp" #include "boost/mpl/aux_/lambda_support.hpp" namespace boost { namespace mpl { -namespace aux { -/* -template< typename LastIterator > -struct find_if_pred -{ - template< - typename Predicate - , typename Iterator - > - struct apply - { - typedef typename not_< or_< - is_same - , aux::iter_apply1 - > >::type type; - }; -}; -*/ -} // namespace aux - BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN template< @@ -56,22 +36,23 @@ template< > struct find_if { - private: - typedef typename begin::type first_; - typedef typename end::type last_; +private: + typedef typename lambda::type pred_; - public: - typedef typename aux::iter_fold_if_impl< - first_ + typedef typename iter_fold_if< + Sequence , void - , mpl::arg<1> - , aux::find_if_pred< pred_, last_ > - , void - , always - >::iterator type; + , protect< arg<1> > // ignore + , protect< aux::find_if_pred > + >::type result_; + +public: + + typedef typename result_::second type; BOOST_MPL_AUX_LAMBDA_SUPPORT(2,find_if,(Sequence,Predicate)) + }; BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END diff --git a/include/boost/mpl/index_if.hpp b/include/boost/mpl/index_if.hpp index 2740788..ead1b6b 100644 --- a/include/boost/mpl/index_if.hpp +++ b/include/boost/mpl/index_if.hpp @@ -57,29 +57,29 @@ struct index_if { private: - typedef typename begin::type first_; - typedef typename end::type last_; typedef typename lambda::type pred_; typedef typename iter_fold_if< - first_ + Sequence , int_<0> , protect< aux::index_if_op > - , protect< aux::find_if_pred > + , protect< aux::find_if_pred > >::type result_; + typedef typename end::type not_found_; typedef typename result_::first result_index_; typedef typename result_::second result_iterator_; public: typedef typename if_< - is_same< result_iterator_,last_ > + is_same< result_iterator_,not_found_ > , void_ , result_index_ >::type type; BOOST_MPL_AUX_LAMBDA_SUPPORT(2,index_if,(Sequence,Predicate)) + }; BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END diff --git a/include/boost/mpl/iter_fold_if.hpp b/include/boost/mpl/iter_fold_if.hpp index 3c2a332..02aabf6 100644 --- a/include/boost/mpl/iter_fold_if.hpp +++ b/include/boost/mpl/iter_fold_if.hpp @@ -4,7 +4,7 @@ //----------------------------------------------------------------------------- // // Copyright (c) 2003 -// Eric Friedman +// Eric Friedman, Aleksey Gurtovoy // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, @@ -18,29 +18,65 @@ #define BOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED #include "boost/mpl/aux_/iter_fold_if_impl.hpp" +#include "boost/mpl/and.hpp" #include "boost/mpl/always.hpp" +#include "boost/mpl/apply.hpp" +#include "boost/mpl/apply_if.hpp" +#include "boost/mpl/begin_end.hpp" #include "boost/mpl/bool.hpp" +#include "boost/mpl/if.hpp" #include "boost/mpl/lambda.hpp" +#include "boost/mpl/not.hpp" #include "boost/mpl/pair.hpp" #include "boost/mpl/void.hpp" #include "boost/mpl/aux_/void_spec.hpp" #include "boost/mpl/aux_/lambda_support.hpp" +#include "boost/type_traits/is_same.hpp" namespace boost { namespace mpl { +namespace aux { + +template< typename Predicate, typename LastIterator > +struct iter_fold_if_pred +{ + template< typename State, typename Iterator > + struct apply + { + typedef and_< + not_< is_same > + , apply1 + > type; + }; +}; + +} // namespace aux + template< - typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Iterator) + typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(State) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(ForwardOp) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(ForwardPredicate) , typename BackwardOp = void_ - , typename BackwardPredicate = always + , typename BackwardPredicate = void_ > struct iter_fold_if { private: + typedef typename begin::type first_; + typedef typename end::type last_; + typedef typename lambda::type forward_op_; + typedef typename lambda::type forward_pred_; + typedef typename lambda::type backward_op_; + + typedef typename apply_if< + is_void_ + , if_< is_void_, always, always > + , lambda + >::type backward_pred_; + // cwpro8 doesn't like 'cut-off' type here (use typedef instead) #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) struct result_ : @@ -48,12 +84,12 @@ private: typedef #endif aux::iter_fold_if_impl< - Iterator + first_ , State - , typename lambda::type - , typename lambda::type - , typename lambda::type - , typename lambda::type + , forward_op_ + , aux::iter_fold_if_pred< forward_pred_,last_ > + , backward_op_ + , backward_pred_ > #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) { }; @@ -71,7 +107,7 @@ public: BOOST_MPL_AUX_LAMBDA_SUPPORT( 6 , iter_fold_if - , (Iterator,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate) + , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate) ) };