From f873abf4a617081f181d1bcbf7d471b30dd03f02 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 8 Dec 2002 07:59:19 +0000 Subject: [PATCH] stripped down implementation for Borland [SVN r16530] --- include/boost/mpl/lower_bound.hpp | 149 +++++++++++++++++++----------- include/boost/mpl/upper_bound.hpp | 146 ++++++++++++++++++----------- 2 files changed, 191 insertions(+), 104 deletions(-) diff --git a/include/boost/mpl/lower_bound.hpp b/include/boost/mpl/lower_bound.hpp index cf210fd..bc2a764 100644 --- a/include/boost/mpl/lower_bound.hpp +++ b/include/boost/mpl/lower_bound.hpp @@ -17,85 +17,130 @@ #ifndef BOOST_MPL_LOWER_BOUND_HPP_INCLUDED #define BOOST_MPL_LOWER_BOUND_HPP_INCLUDED -#include "boost/mpl/size.hpp" -#include "boost/mpl/advance.hpp" -#include "boost/mpl/begin_end.hpp" -#include "boost/mpl/integral_c.hpp" +#include "boost/mpl/comparison/less.hpp" #include "boost/mpl/lambda.hpp" -#include "boost/mpl/apply_if.hpp" -#include "boost/mpl/aux_/apply.hpp" -#include "boost/mpl/aux_/deref_wknd.hpp" -#include "boost/mpl/aux_/value_wknd.hpp" #include "boost/mpl/aux_/void_spec.hpp" +#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x561 || !defined(BOOST_STRICT_CONFIG)) +# define BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL +#endif + +#if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL) +# include "boost/mpl/arithmetic/minus.hpp" +# include "boost/mpl/arithmetic/divides.hpp" +# include "boost/mpl/size.hpp" +# include "boost/mpl/advance.hpp" +# include "boost/mpl/begin_end.hpp" +# include "boost/mpl/integral_c.hpp" +# include "boost/mpl/int_c.hpp" +# include "boost/mpl/apply_if.hpp" +# include "boost/mpl/apply.hpp" +# include "boost/mpl/aux_/apply.hpp" +# include "boost/mpl/aux_/deref_wknd.hpp" +# include "boost/mpl/aux_/value_wknd.hpp" +#else +# include "boost/mpl/logical/not.hpp" +# include "boost/mpl/find.hpp" +# include "boost/mpl/bind.hpp" +#endif + +#include "boost/config.hpp" + namespace boost { namespace mpl { +#if defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL) + +// agurt 23/oct/02: has a wrong complexity etc., but at least it works +// feel free to contribute a better implementation! +template< + typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) + , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) + , typename Predicate = less<> + , typename pred_ = typename lambda::type + > +struct lower_bound + : find_if< Sequence, bind1< logical_not<>, bind2 > > +{ +}; + +#else + namespace aux { -// agurt, 31/mar/02: to workwaround VC7.0 early template instantiation bug -template< long Distance > -struct lower_bound_step; +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > +struct lower_bound_step_impl; -template<> -struct lower_bound_step<0> -{ - template< - typename Predicate - , typename T - , typename DeferredIterator - > - struct result_ - { - typedef typename DeferredIterator::type type; - }; -}; - -template< long Distance > +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > struct lower_bound_step { - template< - typename Predicate - , typename T - , typename DeferredIterator - > - struct result_ - { - typedef integral_c offset_; - typedef typename DeferredIterator::type iter_; - typedef typename advance::type middle_; - typedef typename apply_if< - typename BOOST_MPL_AUX_APPLY2( - Predicate - , typename BOOST_MPL_AUX_DEREF_WNKD(middle_) - , T - )::type - , typename lower_bound_step< Distance - BOOST_MPL_AUX_VALUE_WKND(offset_)::value - 1 > - ::template result_< Predicate,T,next > - , typename lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value > - ::template result_< Predicate,T,DeferredIterator > - >::type type; - }; + typedef typename apply_if< + Distance + , lower_bound_step_impl + , apply0 + >::type type; }; + +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > +struct lower_bound_step_impl +{ + typedef typename divides< Distance, integral_c >::type offset_; + typedef typename DeferredIterator::type iter_; + typedef typename advance< iter_,offset_ >::type middle_; + typedef typename BOOST_MPL_AUX_APPLY2( + Predicate + , typename BOOST_MPL_AUX_DEREF_WNKD(middle_) + , T + )::type cond_; + + typedef typename minus< Distance, offset_, integral_c >::type step_; + typedef lower_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_; + typedef lower_bound_step< step_,Predicate,T,next > step_backward_; + typedef typename apply_if< + cond_ + , step_backward_ + , step_forward_ + >::type type; +}; + } // namespace aux template< typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) - , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate) + , typename Predicate = less<> > struct lower_bound { private: typedef typename lambda::type pred_; + typedef typename size::type size_; public: - typedef typename aux::lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(size)::value > - ::template result_< pred_,T,begin >::type type; + typedef typename aux::lower_bound_step< + size_,pred_,T,begin + >::type type; }; -BOOST_MPL_AUX_VOID_SPEC(3, lower_bound) +#endif // BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL + +BOOST_MPL_AUX_VOID_SPEC(2, lower_bound) } // namespace mpl } // namespace boost diff --git a/include/boost/mpl/upper_bound.hpp b/include/boost/mpl/upper_bound.hpp index f1c6a00..f1fae44 100644 --- a/include/boost/mpl/upper_bound.hpp +++ b/include/boost/mpl/upper_bound.hpp @@ -17,66 +17,104 @@ #ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED #define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED -#include "boost/mpl/size.hpp" -#include "boost/mpl/advance.hpp" -#include "boost/mpl/begin_end.hpp" -#include "boost/mpl/integral_c.hpp" +#include "boost/mpl/comparison/less.hpp" #include "boost/mpl/lambda.hpp" -#include "boost/mpl/apply_if.hpp" -#include "boost/mpl/apply.hpp" -#include "boost/mpl/aux_/apply.hpp" -#include "boost/mpl/aux_/deref_wknd.hpp" -#include "boost/mpl/aux_/value_wknd.hpp" #include "boost/mpl/aux_/void_spec.hpp" +#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x561 || !defined(BOOST_STRICT_CONFIG)) +# define BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL +#endif + +#if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL) +# include "boost/mpl/arithmetic/minus.hpp" +# include "boost/mpl/arithmetic/divides.hpp" +# include "boost/mpl/size.hpp" +# include "boost/mpl/advance.hpp" +# include "boost/mpl/begin_end.hpp" +# include "boost/mpl/integral_c.hpp" +# include "boost/mpl/int_c.hpp" +# include "boost/mpl/apply_if.hpp" +# include "boost/mpl/apply.hpp" +# include "boost/mpl/aux_/apply.hpp" +# include "boost/mpl/aux_/deref_wknd.hpp" +# include "boost/mpl/aux_/value_wknd.hpp" +#else +# include "boost/mpl/find.hpp" +# include "boost/mpl/bind.hpp" +#endif + +#include "boost/config.hpp" + namespace boost { namespace mpl { -namespace aux { +#if defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL) -// agurt, 31/mar/02: to workwaround VC7.0 early template instantiation bug -template< long Distance > -struct upper_bound_step; - -template<> -struct upper_bound_step<0> +// agurt 23/oct/02: has a wrong complexity etc., but at least it works; +// feel free to contribute a better implementation! +template< + typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) + , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) + , typename Predicate = less<> + , typename pred_ = typename lambda::type + > +struct upper_bound + : find_if< Sequence, bind2 > { - template< - typename Predicate - , typename T - , typename DeferredIterator - > - struct result_ - { - typedef typename DeferredIterator::type type; - }; }; -template< long Distance > +#else + +namespace aux { + +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > +struct upper_bound_step_impl; + +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > struct upper_bound_step { - template< - typename Predicate - , typename T - , typename DeferredIterator - > - struct result_ - { - typedef integral_c offset_; - typedef typename DeferredIterator::type iter_; - typedef typename advance::type middle_; - typedef typename apply_if< - typename BOOST_MPL_AUX_APPLY2( - Predicate - , T - , typename BOOST_MPL_AUX_DEREF_WNKD(middle_) - )::type - , typename upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value > - ::template result_< Predicate,T,DeferredIterator > - , typename upper_bound_step< Distance - BOOST_MPL_AUX_VALUE_WKND(offset_)::value - 1 > - ::template result_< Predicate,T,next > - >::type type; - }; + typedef typename apply_if< + Distance + , upper_bound_step_impl + , apply0 + >::type type; +}; + +template< + typename Distance + , typename Predicate + , typename T + , typename DeferredIterator + > +struct upper_bound_step_impl +{ + typedef typename divides< Distance, integral_c >::type offset_; + typedef typename DeferredIterator::type iter_; + typedef typename advance< iter_,offset_ >::type middle_; + typedef typename BOOST_MPL_AUX_APPLY2( + Predicate + , T + , typename BOOST_MPL_AUX_DEREF_WNKD(middle_) + )::type cond_; + + typedef typename minus< Distance, offset_, integral_c >::type step_; + typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_; + typedef upper_bound_step< step_,Predicate,T,next > step_backward_; + typedef typename apply_if< + cond_ + , step_forward_ + , step_backward_ + >::type type; }; } // namespace aux @@ -84,19 +122,23 @@ struct upper_bound_step template< typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) - , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate) + , typename Predicate = less<> > struct upper_bound { private: typedef typename lambda::type pred_; + typedef typename size::type size_; public: - typedef typename aux::upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(size)::value > - ::template result_< pred_,T,begin >::type type; + typedef typename aux::upper_bound_step< + size_,pred_,T,begin + >::type type; }; -BOOST_MPL_AUX_VOID_SPEC(3, upper_bound) +#endif // BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL + +BOOST_MPL_AUX_VOID_SPEC(2, upper_bound) } // namespace mpl } // namespace boost