~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to boost/boost/mpl/upper_bound.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
// boost mpl/upper_bound.hpp header file
 
3
// See http://www.boost.org for updates, documentation, and revision history.
 
4
//-----------------------------------------------------------------------------
 
5
//
 
6
// Copyright (c) 2001-02
 
7
// Aleksey Gurtovoy
 
8
//
 
9
// Permission to use, copy, modify, distribute and sell this software
 
10
// and its documentation for any purpose is hereby granted without fee, 
 
11
// provided that the above copyright notice appears in all copies and 
 
12
// that both the copyright notice and this permission notice appear in 
 
13
// supporting documentation. No representations are made about the 
 
14
// suitability of this software for any purpose. It is provided "as is" 
 
15
// without express or implied warranty.
 
16
 
 
17
#ifndef BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
 
18
#define BOOST_MPL_UPPER_BOUND_HPP_INCLUDED
 
19
 
 
20
#include "boost/mpl/less.hpp"
 
21
#include "boost/mpl/lambda.hpp"
 
22
#include "boost/mpl/aux_/void_spec.hpp"
 
23
 
 
24
#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x561 || !defined(BOOST_STRICT_CONFIG))
 
25
#   define BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
 
26
#endif
 
27
 
 
28
#if !defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
 
29
#   include "boost/mpl/minus.hpp"
 
30
#   include "boost/mpl/divides.hpp"
 
31
#   include "boost/mpl/size.hpp"
 
32
#   include "boost/mpl/advance.hpp"
 
33
#   include "boost/mpl/begin_end.hpp"
 
34
#   include "boost/mpl/integral_c.hpp"
 
35
#   include "boost/mpl/int.hpp"
 
36
#   include "boost/mpl/apply_if.hpp"
 
37
#   include "boost/mpl/apply.hpp"
 
38
#   include "boost/mpl/aux_/apply.hpp"
 
39
#   include "boost/mpl/aux_/deref_wknd.hpp"
 
40
#   include "boost/mpl/aux_/value_wknd.hpp"
 
41
#else
 
42
#   include "boost/mpl/find.hpp"
 
43
#   include "boost/mpl/bind.hpp"
 
44
#endif
 
45
 
 
46
#include "boost/config.hpp"
 
47
 
 
48
namespace boost {
 
49
namespace mpl {
 
50
 
 
51
#if defined(BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL)
 
52
 
 
53
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
 
54
 
 
55
// agurt 23/oct/02: has a wrong complexity etc., but at least it works;
 
56
// feel free to contribute a better implementation!
 
57
template<
 
58
      typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
 
59
    , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
 
60
    , typename Predicate = less<>
 
61
    , typename pred_ = typename lambda<Predicate>::type
 
62
    >
 
63
struct upper_bound
 
64
    : find_if< Sequence, bind2<pred_,T,_> >
 
65
{
 
66
};
 
67
 
 
68
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
 
69
 
 
70
#else
 
71
 
 
72
namespace aux {
 
73
 
 
74
template<
 
75
      typename Distance
 
76
    , typename Predicate
 
77
    , typename T
 
78
    , typename DeferredIterator
 
79
    >
 
80
struct upper_bound_step_impl;
 
81
 
 
82
template< 
 
83
      typename Distance
 
84
    , typename Predicate
 
85
    , typename T
 
86
    , typename DeferredIterator
 
87
    >
 
88
struct upper_bound_step
 
89
{
 
90
    typedef typename apply_if<
 
91
          Distance
 
92
        , upper_bound_step_impl<Distance,Predicate,T,DeferredIterator>
 
93
        , apply0<DeferredIterator>
 
94
        >::type type;
 
95
};
 
96
    
 
97
template<
 
98
      typename Distance
 
99
    , typename Predicate
 
100
    , typename T
 
101
    , typename DeferredIterator
 
102
    >
 
103
struct upper_bound_step_impl
 
104
{
 
105
    typedef typename divides< Distance, integral_c<long,2> >::type offset_;
 
106
    typedef typename DeferredIterator::type iter_;
 
107
    typedef typename advance< iter_,offset_ >::type middle_;
 
108
    typedef typename BOOST_MPL_AUX_APPLY2(
 
109
              Predicate
 
110
            , T
 
111
            , typename BOOST_MPL_AUX_DEREF_WNKD(middle_)
 
112
            )::type cond_;
 
113
 
 
114
    typedef typename minus< Distance, offset_, integral_c<long,1> >::type step_;
 
115
    typedef upper_bound_step< offset_,Predicate,T,DeferredIterator > step_forward_;
 
116
    typedef upper_bound_step< step_,Predicate,T,next<middle_> > step_backward_;
 
117
    typedef typename apply_if<
 
118
          cond_
 
119
        , step_forward_
 
120
        , step_backward_
 
121
        >::type type;
 
122
};
 
123
 
 
124
} // namespace aux
 
125
 
 
126
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
 
127
 
 
128
template<
 
129
      typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
 
130
    , typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
 
131
    , typename Predicate = less<>
 
132
    >
 
133
struct upper_bound
 
134
{
 
135
 private:
 
136
    typedef typename lambda<Predicate>::type pred_;
 
137
    typedef typename size<Sequence>::type size_;
 
138
 
 
139
 public:
 
140
    typedef typename aux::upper_bound_step<
 
141
        size_,pred_,T,begin<Sequence>
 
142
        >::type type;
 
143
};
 
144
 
 
145
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
 
146
 
 
147
#endif // BOOST_MPL_CFG_STRIPPED_DOWN_UPPER_BOUND_IMPL
 
148
 
 
149
BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(2, upper_bound)
 
150
 
 
151
} // namespace mpl
 
152
} // namespace boost
 
153
 
 
154
#endif // BOOST_MPL_UPPER_BOUND_HPP_INCLUDED