Files
boost_mpl/include/boost/mpl/lower_bound.hpp
T

144 lines
3.5 KiB
C++
Raw Normal View History

2002-09-15 22:13:24 +00:00
#ifndef BOOST_MPL_LOWER_BOUND_HPP_INCLUDED
#define BOOST_MPL_LOWER_BOUND_HPP_INCLUDED
2004-09-02 15:41:37 +00:00
// Copyright Aleksey Gurtovoy 2001-2004
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
// $Source$
// $Date$
// $Revision$
#include <boost/mpl/less.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/aux_/na_spec.hpp>
#include <boost/mpl/aux_/config/workaround.hpp>
#if BOOST_WORKAROUND(__BORLANDC__, < 0x600)
2002-12-08 07:59:19 +00:00
# define BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL
#endif
#if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL)
2004-09-02 15:41:37 +00:00
# include <boost/mpl/minus.hpp>
# include <boost/mpl/divides.hpp>
# include <boost/mpl/size.hpp>
# include <boost/mpl/advance.hpp>
# include <boost/mpl/begin_end.hpp>
# include <boost/mpl/long.hpp>
# include <boost/mpl/eval_if.hpp>
# include <boost/mpl/prior.hpp>
# include <boost/mpl/deref.hpp>
# include <boost/mpl/apply.hpp>
# include <boost/mpl/aux_/value_wknd.hpp>
2002-12-08 07:59:19 +00:00
#else
2004-09-02 15:41:37 +00:00
# include <boost/mpl/not.hpp>
# include <boost/mpl/find.hpp>
# include <boost/mpl/bind.hpp>
2002-12-08 07:59:19 +00:00
#endif
2004-09-02 15:41:37 +00:00
#include <boost/config.hpp>
2002-12-08 07:59:19 +00:00
2004-09-02 15:41:37 +00:00
namespace boost { namespace mpl {
2002-09-15 22:13:24 +00:00
2002-12-08 07:59:19 +00:00
#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<
2004-09-02 15:41:37 +00:00
typename BOOST_MPL_AUX_NA_PARAM(Sequence)
, typename BOOST_MPL_AUX_NA_PARAM(T)
2002-12-08 07:59:19 +00:00
, typename Predicate = less<>
, typename pred_ = typename lambda<Predicate>::type
>
struct lower_bound
2003-02-25 23:11:41 +00:00
: find_if< Sequence, bind1< not_<>, bind2<pred_,_,T> > >
2002-12-08 07:59:19 +00:00
{
};
#else
2002-09-15 22:13:24 +00:00
namespace aux {
2002-12-08 07:59:19 +00:00
template<
typename Distance
, typename Predicate
, typename T
, typename DeferredIterator
>
struct lower_bound_step_impl;
2002-09-15 22:13:24 +00:00
2002-12-08 07:59:19 +00:00
template<
typename Distance
, typename Predicate
, typename T
, typename DeferredIterator
>
2002-09-15 22:13:24 +00:00
struct lower_bound_step
{
2004-09-02 15:41:37 +00:00
typedef typename eval_if<
2002-12-08 07:59:19 +00:00
Distance
, lower_bound_step_impl<Distance,Predicate,T,DeferredIterator>
2004-09-02 15:41:37 +00:00
, DeferredIterator
2002-12-08 07:59:19 +00:00
>::type type;
2002-09-15 22:13:24 +00:00
};
2002-12-08 07:59:19 +00:00
template<
typename Distance
, typename Predicate
, typename T
, typename DeferredIterator
>
struct lower_bound_step_impl
{
2004-09-02 15:41:37 +00:00
typedef typename divides< Distance, long_<2> >::type offset_;
2002-12-08 07:59:19 +00:00
typedef typename DeferredIterator::type iter_;
typedef typename advance< iter_,offset_ >::type middle_;
2004-09-02 15:41:37 +00:00
typedef typename apply2<
2002-12-08 07:59:19 +00:00
Predicate
2004-09-02 15:41:37 +00:00
, typename deref<middle_>::type
2002-12-08 07:59:19 +00:00
, T
2004-09-02 15:41:37 +00:00
>::type cond_;
2002-12-08 07:59:19 +00:00
2004-09-02 15:41:37 +00:00
typedef typename prior< minus< Distance, offset_> >::type step_;
2002-12-08 07:59:19 +00:00
typedef lower_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
typedef lower_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
2004-09-02 15:41:37 +00:00
typedef typename eval_if<
2002-12-08 07:59:19 +00:00
cond_
, step_backward_
, step_forward_
>::type type;
};
2002-09-15 22:13:24 +00:00
} // namespace aux
template<
2004-09-02 15:41:37 +00:00
typename BOOST_MPL_AUX_NA_PARAM(Sequence)
, typename BOOST_MPL_AUX_NA_PARAM(T)
2002-12-08 07:59:19 +00:00
, typename Predicate = less<>
2002-09-15 22:13:24 +00:00
>
struct lower_bound
{
private:
typedef typename lambda<Predicate>::type pred_;
2002-12-08 07:59:19 +00:00
typedef typename size<Sequence>::type size_;
2002-09-15 22:13:24 +00:00
public:
2002-12-08 07:59:19 +00:00
typedef typename aux::lower_bound_step<
size_,pred_,T,begin<Sequence>
>::type type;
2002-09-15 22:13:24 +00:00
};
2002-12-08 07:59:19 +00:00
#endif // BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL
2004-09-02 15:41:37 +00:00
BOOST_MPL_AUX_NA_SPEC(2, lower_bound)
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
}}
2002-09-15 22:13:24 +00:00
#endif // BOOST_MPL_LOWER_BOUND_HPP_INCLUDED