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 {
#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<Predicate>::type
>
struct lower_bound
: find_if< Sequence, bind1< logical_not<>, bind2<pred_,_,T> > >
{
};
#else
namespace aux { namespace aux {
// agurt, 31/mar/02: to workwaround VC7.0 early template instantiation bug template<
template< long Distance > typename Distance
struct lower_bound_step; , typename Predicate
, typename T
, typename DeferredIterator
>
struct lower_bound_step_impl;
template<> template<
struct lower_bound_step<0> typename Distance
{ , typename Predicate
template< , typename T
typename Predicate , typename DeferredIterator
, typename T >
, typename DeferredIterator
>
struct result_
{
typedef typename DeferredIterator::type type;
};
};
template< long Distance >
struct lower_bound_step struct lower_bound_step
{ {
template< typedef typename apply_if<
typename Predicate Distance
, typename T , lower_bound_step_impl<Distance,Predicate,T,DeferredIterator>
, typename DeferredIterator , apply0<DeferredIterator>
> >::type type;
struct result_
{
typedef integral_c<long, Distance / 2> offset_;
typedef typename DeferredIterator::type iter_;
typedef typename advance<iter_, offset_>::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<middle_> >
, typename lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value >
::template result_< Predicate,T,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
, typename BOOST_MPL_AUX_DEREF_WNKD(middle_)
, T
)::type cond_;
typedef typename minus< Distance, offset_, integral_c<long,1> >::type step_;
typedef lower_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
typedef lower_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
typedef typename apply_if<
cond_
, step_backward_
, step_forward_
>::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
>
struct upper_bound
: find_if< Sequence, bind2<pred_,T,_> >
{ {
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 struct upper_bound_step
{ {
template< typedef typename apply_if<
typename Predicate Distance
, typename T , upper_bound_step_impl<Distance,Predicate,T,DeferredIterator>
, typename DeferredIterator , apply0<DeferredIterator>
> >::type type;
struct result_ };
{
typedef integral_c<long, Distance / 2> offset_; template<
typedef typename DeferredIterator::type iter_; typename Distance
typedef typename advance<iter_, offset_>::type middle_; , typename Predicate
typedef typename apply_if< , typename T
typename BOOST_MPL_AUX_APPLY2( , typename DeferredIterator
Predicate >
, T struct upper_bound_step_impl
, typename BOOST_MPL_AUX_DEREF_WNKD(middle_) {
)::type typedef typename divides< Distance, integral_c<long,2> >::type offset_;
, typename upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(offset_)::value > typedef typename DeferredIterator::type iter_;
::template result_< Predicate,T,DeferredIterator > typedef typename advance< iter_,offset_ >::type middle_;
, typename upper_bound_step< Distance - BOOST_MPL_AUX_VALUE_WKND(offset_)::value - 1 > typedef typename BOOST_MPL_AUX_APPLY2(
::template result_< Predicate,T,next<middle_> > Predicate
>::type type; , T
}; , typename BOOST_MPL_AUX_DEREF_WNKD(middle_)
)::type cond_;
typedef typename minus< Distance, offset_, integral_c<long,1> >::type step_;
typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
typedef upper_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
typedef typename apply_if<
cond_
, step_forward_
, step_backward_
>::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