mirror of
https://github.com/boostorg/mpl.git
synced 2025-08-03 23:04:33 +02:00
stripped down implementation for Borland
[SVN r16530]
This commit is contained in:
@@ -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<Predicate>::type
|
||||
>
|
||||
struct lower_bound
|
||||
: find_if< Sequence, bind1< logical_not<>, bind2<pred_,_,T> > >
|
||||
{
|
||||
};
|
||||
|
||||
#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<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;
|
||||
};
|
||||
typedef typename apply_if<
|
||||
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
|
||||
, 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
|
||||
|
||||
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<Predicate>::type pred_;
|
||||
typedef typename size<Sequence>::type size_;
|
||||
|
||||
public:
|
||||
typedef typename aux::lower_bound_step< BOOST_MPL_AUX_VALUE_WKND(size<Sequence>)::value >
|
||||
::template result_< pred_,T,begin<Sequence> >::type type;
|
||||
typedef typename aux::lower_bound_step<
|
||||
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 boost
|
||||
|
@@ -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<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
|
||||
{
|
||||
template<
|
||||
typename Predicate
|
||||
, typename T
|
||||
, typename DeferredIterator
|
||||
>
|
||||
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
|
||||
, 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<middle_> >
|
||||
>::type type;
|
||||
};
|
||||
typedef typename apply_if<
|
||||
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
|
||||
, 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
|
||||
@@ -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<Predicate>::type pred_;
|
||||
typedef typename size<Sequence>::type size_;
|
||||
|
||||
public:
|
||||
typedef typename aux::upper_bound_step< BOOST_MPL_AUX_VALUE_WKND(size<Sequence>)::value >
|
||||
::template result_< pred_,T,begin<Sequence> >::type type;
|
||||
typedef typename aux::upper_bound_step<
|
||||
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 boost
|
||||
|
Reference in New Issue
Block a user