Chris@16
|
1
|
Chris@16
|
2 #ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
|
Chris@16
|
3 #define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
|
Chris@16
|
4
|
Chris@16
|
5 // Copyright Aleksey Gurtovoy 2001-2004
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
8 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
9 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10 //
|
Chris@16
|
11 // See http://www.boost.org/libs/mpl for documentation.
|
Chris@16
|
12
|
Chris@101
|
13 // $Id$
|
Chris@101
|
14 // $Date$
|
Chris@101
|
15 // $Revision$
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/mpl/less.hpp>
|
Chris@16
|
18 #include <boost/mpl/lambda.hpp>
|
Chris@16
|
19 #include <boost/mpl/aux_/na_spec.hpp>
|
Chris@16
|
20 #include <boost/mpl/aux_/config/workaround.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610))
|
Chris@16
|
23 # define BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
|
Chris@16
|
24 #endif
|
Chris@16
|
25
|
Chris@16
|
26 #if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
|
Chris@16
|
27 # include <boost/mpl/minus.hpp>
|
Chris@16
|
28 # include <boost/mpl/divides.hpp>
|
Chris@16
|
29 # include <boost/mpl/size.hpp>
|
Chris@16
|
30 # include <boost/mpl/advance.hpp>
|
Chris@16
|
31 # include <boost/mpl/begin_end.hpp>
|
Chris@16
|
32 # include <boost/mpl/long.hpp>
|
Chris@16
|
33 # include <boost/mpl/eval_if.hpp>
|
Chris@16
|
34 # include <boost/mpl/prior.hpp>
|
Chris@16
|
35 # include <boost/mpl/deref.hpp>
|
Chris@16
|
36 # include <boost/mpl/apply.hpp>
|
Chris@16
|
37 # include <boost/mpl/aux_/value_wknd.hpp>
|
Chris@16
|
38 #else
|
Chris@16
|
39 # include <boost/mpl/find.hpp>
|
Chris@16
|
40 # include <boost/mpl/bind.hpp>
|
Chris@16
|
41 #endif
|
Chris@16
|
42
|
Chris@16
|
43 #include <boost/config.hpp>
|
Chris@16
|
44
|
Chris@16
|
45 namespace boost { namespace mpl {
|
Chris@16
|
46
|
Chris@16
|
47 #if defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
|
Chris@16
|
48
|
Chris@16
|
49 // agurt 23/oct/02: has a wrong complexity etc., but at least it works;
|
Chris@16
|
50 // feel free to contribute a better implementation!
|
Chris@16
|
51 template<
|
Chris@16
|
52 typename BOOST_MPL_AUX_NA_PARAM(Sequence)
|
Chris@16
|
53 , typename BOOST_MPL_AUX_NA_PARAM(T)
|
Chris@16
|
54 , typename Predicate = less<>
|
Chris@16
|
55 , typename pred_ = typename lambda<Predicate>::type
|
Chris@16
|
56 >
|
Chris@16
|
57 struct upper_bound
|
Chris@16
|
58 : find_if< Sequence, bind2<pred_,T,_> >
|
Chris@16
|
59 {
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 #else
|
Chris@16
|
63
|
Chris@16
|
64 namespace aux {
|
Chris@16
|
65
|
Chris@16
|
66 template<
|
Chris@16
|
67 typename Distance
|
Chris@16
|
68 , typename Predicate
|
Chris@16
|
69 , typename T
|
Chris@16
|
70 , typename DeferredIterator
|
Chris@16
|
71 >
|
Chris@16
|
72 struct upper_bound_step_impl;
|
Chris@16
|
73
|
Chris@16
|
74 template<
|
Chris@16
|
75 typename Distance
|
Chris@16
|
76 , typename Predicate
|
Chris@16
|
77 , typename T
|
Chris@16
|
78 , typename DeferredIterator
|
Chris@16
|
79 >
|
Chris@16
|
80 struct upper_bound_step
|
Chris@16
|
81 {
|
Chris@16
|
82 typedef typename eval_if<
|
Chris@16
|
83 Distance
|
Chris@16
|
84 , upper_bound_step_impl<Distance,Predicate,T,DeferredIterator>
|
Chris@16
|
85 , DeferredIterator
|
Chris@16
|
86 >::type type;
|
Chris@16
|
87 };
|
Chris@16
|
88
|
Chris@16
|
89 template<
|
Chris@16
|
90 typename Distance
|
Chris@16
|
91 , typename Predicate
|
Chris@16
|
92 , typename T
|
Chris@16
|
93 , typename DeferredIterator
|
Chris@16
|
94 >
|
Chris@16
|
95 struct upper_bound_step_impl
|
Chris@16
|
96 {
|
Chris@16
|
97 typedef typename divides< Distance, long_<2> >::type offset_;
|
Chris@16
|
98 typedef typename DeferredIterator::type iter_;
|
Chris@16
|
99 typedef typename advance< iter_,offset_ >::type middle_;
|
Chris@16
|
100 typedef typename apply2<
|
Chris@16
|
101 Predicate
|
Chris@16
|
102 , T
|
Chris@16
|
103 , typename deref<middle_>::type
|
Chris@16
|
104 >::type cond_;
|
Chris@16
|
105
|
Chris@16
|
106 typedef typename prior< minus< Distance, offset_ > >::type step_;
|
Chris@16
|
107 typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
|
Chris@16
|
108 typedef upper_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
|
Chris@16
|
109 typedef typename eval_if<
|
Chris@16
|
110 cond_
|
Chris@16
|
111 , step_forward_
|
Chris@16
|
112 , step_backward_
|
Chris@16
|
113 >::type type;
|
Chris@16
|
114 };
|
Chris@16
|
115
|
Chris@16
|
116 } // namespace aux
|
Chris@16
|
117
|
Chris@16
|
118 template<
|
Chris@16
|
119 typename BOOST_MPL_AUX_NA_PARAM(Sequence)
|
Chris@16
|
120 , typename BOOST_MPL_AUX_NA_PARAM(T)
|
Chris@16
|
121 , typename Predicate = less<>
|
Chris@16
|
122 >
|
Chris@16
|
123 struct upper_bound
|
Chris@16
|
124 {
|
Chris@16
|
125 private:
|
Chris@16
|
126 typedef typename lambda<Predicate>::type pred_;
|
Chris@16
|
127 typedef typename size<Sequence>::type size_;
|
Chris@16
|
128
|
Chris@16
|
129 public:
|
Chris@16
|
130 typedef typename aux::upper_bound_step<
|
Chris@16
|
131 size_,pred_,T,begin<Sequence>
|
Chris@16
|
132 >::type type;
|
Chris@16
|
133 };
|
Chris@16
|
134
|
Chris@16
|
135 #endif // BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
|
Chris@16
|
136
|
Chris@16
|
137 BOOST_MPL_AUX_NA_SPEC(2, upper_bound)
|
Chris@16
|
138
|
Chris@16
|
139 }}
|
Chris@16
|
140
|
Chris@16
|
141 #endif // BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
|