2 #ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
\r
3 #define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
\r
5 // Copyright Aleksey Gurtovoy 2001-2004
\r
7 // Distributed under the Boost Software License, Version 1.0.
\r
8 // (See accompanying file LICENSE_1_0.txt or copy at
\r
9 // http://www.boost.org/LICENSE_1_0.txt)
\r
11 // See http://www.boost.org/libs/mpl for documentation.
\r
13 // $Id: upper_bound.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
\r
14 // $Date: 2008-10-11 02:19:02 -0400 (Sat, 11 Oct 2008) $
\r
15 // $Revision: 49267 $
\r
17 #include <boost/mpl/less.hpp>
\r
18 #include <boost/mpl/lambda.hpp>
\r
19 #include <boost/mpl/aux_/na_spec.hpp>
\r
20 #include <boost/mpl/aux_/config/workaround.hpp>
\r
22 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610))
\r
23 # define BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
\r
26 #if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
\r
27 # include <boost/mpl/minus.hpp>
\r
28 # include <boost/mpl/divides.hpp>
\r
29 # include <boost/mpl/size.hpp>
\r
30 # include <boost/mpl/advance.hpp>
\r
31 # include <boost/mpl/begin_end.hpp>
\r
32 # include <boost/mpl/long.hpp>
\r
33 # include <boost/mpl/eval_if.hpp>
\r
34 # include <boost/mpl/prior.hpp>
\r
35 # include <boost/mpl/deref.hpp>
\r
36 # include <boost/mpl/apply.hpp>
\r
37 # include <boost/mpl/aux_/value_wknd.hpp>
\r
39 # include <boost/mpl/find.hpp>
\r
40 # include <boost/mpl/bind.hpp>
\r
43 #include <boost/config.hpp>
\r
45 namespace boost { namespace mpl {
\r
47 #if defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
\r
49 // agurt 23/oct/02: has a wrong complexity etc., but at least it works;
\r
50 // feel free to contribute a better implementation!
\r
52 typename BOOST_MPL_AUX_NA_PARAM(Sequence)
\r
53 , typename BOOST_MPL_AUX_NA_PARAM(T)
\r
54 , typename Predicate = less<>
\r
55 , typename pred_ = typename lambda<Predicate>::type
\r
58 : find_if< Sequence, bind2<pred_,T,_> >
\r
68 , typename Predicate
\r
70 , typename DeferredIterator
\r
72 struct upper_bound_step_impl;
\r
76 , typename Predicate
\r
78 , typename DeferredIterator
\r
80 struct upper_bound_step
\r
82 typedef typename eval_if<
\r
84 , upper_bound_step_impl<Distance,Predicate,T,DeferredIterator>
\r
91 , typename Predicate
\r
93 , typename DeferredIterator
\r
95 struct upper_bound_step_impl
\r
97 typedef typename divides< Distance, long_<2> >::type offset_;
\r
98 typedef typename DeferredIterator::type iter_;
\r
99 typedef typename advance< iter_,offset_ >::type middle_;
\r
100 typedef typename apply2<
\r
103 , typename deref<middle_>::type
\r
106 typedef typename prior< minus< Distance, offset_ > >::type step_;
\r
107 typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
\r
108 typedef upper_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
\r
109 typedef typename eval_if<
\r
119 typename BOOST_MPL_AUX_NA_PARAM(Sequence)
\r
120 , typename BOOST_MPL_AUX_NA_PARAM(T)
\r
121 , typename Predicate = less<>
\r
126 typedef typename lambda<Predicate>::type pred_;
\r
127 typedef typename size<Sequence>::type size_;
\r
130 typedef typename aux::upper_bound_step<
\r
131 size_,pred_,T,begin<Sequence>
\r
135 #endif // BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
\r
137 BOOST_MPL_AUX_NA_SPEC(2, upper_bound)
\r
141 #endif // BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
\r