stripped down implementation for Borland

[SVN r16530]
This commit is contained in:
Aleksey Gurtovoy
2002-12-08 07:59:19 +00:00
parent 1433cb707a
commit f873abf4a6
2 changed files with 191 additions and 104 deletions

View File

@@ -17,85 +17,130 @@
#ifndef BOOST_MPL_LOWER_BOUND_HPP_INCLUDED #ifndef BOOST_MPL_LOWER_BOUND_HPP_INCLUDED
#define BOOST_MPL_LOWER_BOUND_HPP_INCLUDED #define BOOST_MPL_LOWER_BOUND_HPP_INCLUDED
#include "boost/mpl/size.hpp" #include "boost/mpl/comparison/less.hpp"
#include "boost/mpl/advance.hpp"
#include "boost/mpl/begin_end.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/mpl/lambda.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" #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 boost {
namespace mpl { namespace mpl {
namespace aux { #if defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL)
// agurt, 31/mar/02: to workwaround VC7.0 early template instantiation bug // agurt 23/oct/02: has a wrong complexity etc., but at least it works
template< long Distance > // feel free to contribute a better implementation!
struct lower_bound_step; template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
template<> , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
struct lower_bound_step<0> , typename Predicate = less<>
{ , typename pred_ = typename lambda<Predicate>::type
template<
typename Predicate
, typename T
, typename DeferredIterator
> >
struct result_ struct lower_bound
{ : find_if< Sequence, bind1< logical_not<>, bind2<pred_,_,T> > >
typedef typename DeferredIterator::type type; {
};
}; };
template< long Distance > #else
struct lower_bound_step
{ namespace aux {
template<
typename Predicate template<
typename Distance
, typename Predicate
, typename T , typename T
, typename DeferredIterator , typename DeferredIterator
> >
struct result_ struct lower_bound_step_impl;
{
typedef integral_c<long, Distance / 2> offset_; template<
typedef typename DeferredIterator::type iter_; typename Distance
typedef typename advance<iter_, offset_>::type middle_; , typename Predicate
, typename T
, typename DeferredIterator
>
struct lower_bound_step
{
typedef typename apply_if< typedef typename apply_if<
typename BOOST_MPL_AUX_APPLY2( Distance
, lower_bound_step_impl<Distance,Predicate,T,DeferredIterator>
, apply0<DeferredIterator>
>::type type;
};
template<
typename Distance
, typename Predicate
, typename T
, typename DeferredIterator
>
struct lower_bound_step_impl
{
typedef typename divides< Distance, integral_c<long,2> >::type offset_;
typedef typename DeferredIterator::type iter_;
typedef typename advance< iter_,offset_ >::type middle_;
typedef typename BOOST_MPL_AUX_APPLY2(
Predicate Predicate
, typename BOOST_MPL_AUX_DEREF_WNKD(middle_) , typename BOOST_MPL_AUX_DEREF_WNKD(middle_)
, T , T
)::type )::type cond_;
, typename lower_bound_step< Distance - BOOST_MPL_AUX_VALUE_WKND(offset_)::value - 1 >
::template result_< Predicate,T,next<middle_> > typedef typename minus< Distance, offset_, integral_c<long,1> >::type step_;
, typename lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value > typedef lower_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
::template result_< Predicate,T,DeferredIterator > typedef lower_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
typedef typename apply_if<
cond_
, step_backward_
, step_forward_
>::type type; >::type type;
};
}; };
} // namespace aux } // namespace aux
template< template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate) , typename Predicate = less<>
> >
struct lower_bound struct lower_bound
{ {
private: private:
typedef typename lambda<Predicate>::type pred_; typedef typename lambda<Predicate>::type pred_;
typedef typename size<Sequence>::type size_;
public: public:
typedef typename aux::lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(size<Sequence>)::value > typedef typename aux::lower_bound_step<
::template result_< pred_,T,begin<Sequence> >::type type; size_,pred_,T,begin<Sequence>
>::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 mpl
} // namespace boost } // namespace boost

View File

@@ -17,66 +17,104 @@
#ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED #ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
#define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED #define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
#include "boost/mpl/size.hpp" #include "boost/mpl/comparison/less.hpp"
#include "boost/mpl/advance.hpp"
#include "boost/mpl/begin_end.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/mpl/lambda.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" #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 boost {
namespace mpl { 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 // agurt 23/oct/02: has a wrong complexity etc., but at least it works;
template< long Distance > // feel free to contribute a better implementation!
struct upper_bound_step; template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
template<> , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
struct upper_bound_step<0> , typename Predicate = less<>
{ , typename pred_ = typename lambda<Predicate>::type
template<
typename Predicate
, typename T
, typename DeferredIterator
> >
struct result_ struct upper_bound
{ : find_if< Sequence, bind2<pred_,T,_> >
typedef typename DeferredIterator::type type; {
};
}; };
template< long Distance > #else
struct upper_bound_step
{ namespace aux {
template<
typename Predicate template<
typename Distance
, typename Predicate
, typename T , typename T
, typename DeferredIterator , typename DeferredIterator
> >
struct result_ struct upper_bound_step_impl;
{
typedef integral_c<long, Distance / 2> offset_; template<
typedef typename DeferredIterator::type iter_; typename Distance
typedef typename advance<iter_, offset_>::type middle_; , typename Predicate
, typename T
, typename DeferredIterator
>
struct upper_bound_step
{
typedef typename apply_if< typedef typename apply_if<
typename BOOST_MPL_AUX_APPLY2( Distance
, upper_bound_step_impl<Distance,Predicate,T,DeferredIterator>
, apply0<DeferredIterator>
>::type type;
};
template<
typename Distance
, typename Predicate
, typename T
, typename DeferredIterator
>
struct upper_bound_step_impl
{
typedef typename divides< Distance, integral_c<long,2> >::type offset_;
typedef typename DeferredIterator::type iter_;
typedef typename advance< iter_,offset_ >::type middle_;
typedef typename BOOST_MPL_AUX_APPLY2(
Predicate Predicate
, T , T
, typename BOOST_MPL_AUX_DEREF_WNKD(middle_) , typename BOOST_MPL_AUX_DEREF_WNKD(middle_)
)::type )::type cond_;
, typename upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value >
::template result_< Predicate,T,DeferredIterator > typedef typename minus< Distance, offset_, integral_c<long,1> >::type step_;
, typename upper_bound_step< Distance - BOOST_MPL_AUX_VALUE_WKND(offset_)::value - 1 > typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
::template result_< Predicate,T,next<middle_> > typedef upper_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
typedef typename apply_if<
cond_
, step_forward_
, step_backward_
>::type type; >::type type;
};
}; };
} // namespace aux } // namespace aux
@@ -84,19 +122,23 @@ struct upper_bound_step
template< template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence) typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate) , typename Predicate = less<>
> >
struct upper_bound struct upper_bound
{ {
private: private:
typedef typename lambda<Predicate>::type pred_; typedef typename lambda<Predicate>::type pred_;
typedef typename size<Sequence>::type size_;
public: public:
typedef typename aux::upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(size<Sequence>)::value > typedef typename aux::upper_bound_step<
::template result_< pred_,T,begin<Sequence> >::type type; size_,pred_,T,begin<Sequence>
>::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 mpl
} // namespace boost } // namespace boost