]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/mpl/lower_bound.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
c3e3d73a4d277797e21ec0a6e49bb5a2d92f0141
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / mpl / lower_bound.hpp
1 \r
2 #ifndef BOOST_MPL_LOWER_BOUND_HPP_INCLUDED\r
3 #define BOOST_MPL_LOWER_BOUND_HPP_INCLUDED\r
4 \r
5 // Copyright Aleksey Gurtovoy 2001-2004\r
6 //\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
10 //\r
11 // See http://www.boost.org/libs/mpl for documentation.\r
12 \r
13 // $Id: lower_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
16 \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
21 \r
22 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610))\r
23 #   define BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL\r
24 #endif\r
25 \r
26 #if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_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
38 #else\r
39 #   include <boost/mpl/not.hpp>\r
40 #   include <boost/mpl/find.hpp>\r
41 #   include <boost/mpl/bind.hpp>\r
42 #endif\r
43 \r
44 #include <boost/config.hpp>\r
45 \r
46 namespace boost { namespace mpl {\r
47 \r
48 #if defined(BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL)\r
49 \r
50 // agurt 23/oct/02: has a wrong complexity etc., but at least it works\r
51 // feel free to contribute a better implementation!\r
52 template<\r
53       typename BOOST_MPL_AUX_NA_PARAM(Sequence)\r
54     , typename BOOST_MPL_AUX_NA_PARAM(T)\r
55     , typename Predicate = less<>\r
56     , typename pred_ = typename lambda<Predicate>::type\r
57     >\r
58 struct lower_bound\r
59     : find_if< Sequence, bind1< not_<>, bind2<pred_,_,T> > >\r
60 {\r
61 };\r
62 \r
63 #else\r
64 \r
65 namespace aux {\r
66 \r
67 template<\r
68       typename Distance\r
69     , typename Predicate\r
70     , typename T\r
71     , typename DeferredIterator\r
72     >\r
73 struct lower_bound_step_impl;\r
74 \r
75 template< \r
76       typename Distance\r
77     , typename Predicate\r
78     , typename T\r
79     , typename DeferredIterator\r
80     >\r
81 struct lower_bound_step\r
82 {\r
83     typedef typename eval_if<\r
84           Distance\r
85         , lower_bound_step_impl<Distance,Predicate,T,DeferredIterator>\r
86         , DeferredIterator\r
87         >::type type;\r
88 };\r
89     \r
90 template<\r
91       typename Distance\r
92     , typename Predicate\r
93     , typename T\r
94     , typename DeferredIterator\r
95     >\r
96 struct lower_bound_step_impl\r
97 {\r
98     typedef typename divides< Distance, long_<2> >::type offset_;\r
99     typedef typename DeferredIterator::type iter_;\r
100     typedef typename advance< iter_,offset_ >::type middle_;\r
101     typedef typename apply2<\r
102               Predicate\r
103             , typename deref<middle_>::type\r
104             , T\r
105             >::type cond_;\r
106 \r
107     typedef typename prior< minus< Distance, offset_> >::type step_;\r
108     typedef lower_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;\r
109     typedef lower_bound_step< step_,Predicate,T,next<middle_> > step_backward_;\r
110     typedef typename eval_if<\r
111           cond_\r
112         , step_backward_\r
113         , step_forward_\r
114         >::type type;\r
115 };\r
116 \r
117 \r
118 } // namespace aux\r
119 \r
120 template<\r
121       typename BOOST_MPL_AUX_NA_PARAM(Sequence)\r
122     , typename BOOST_MPL_AUX_NA_PARAM(T)\r
123     , typename Predicate = less<>\r
124     >\r
125 struct lower_bound\r
126 {\r
127  private:\r
128     typedef typename lambda<Predicate>::type pred_;\r
129     typedef typename size<Sequence>::type size_;\r
130 \r
131  public:\r
132     typedef typename aux::lower_bound_step<\r
133         size_,pred_,T,begin<Sequence>\r
134         >::type type;\r
135 };\r
136 \r
137 #endif // BOOST_MPL_CFG_STRIPPED_DOWN_LOWER_BOUND_IMPL\r
138 \r
139 BOOST_MPL_AUX_NA_SPEC(2, lower_bound)\r
140 \r
141 }}\r
142 \r
143 #endif // BOOST_MPL_LOWER_BOUND_HPP_INCLUDED\r