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