epoc32/include/tools/stlport/stl/_algo.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
/*
williamr@4
     2
 *
williamr@4
     3
 * Copyright (c) 1994
williamr@4
     4
 * Hewlett-Packard Company
williamr@4
     5
 *
williamr@4
     6
 * Copyright (c) 1996,1997
williamr@4
     7
 * Silicon Graphics Computer Systems, Inc.
williamr@4
     8
 *
williamr@4
     9
 * Copyright (c) 1997
williamr@4
    10
 * Moscow Center for SPARC Technology
williamr@4
    11
 *
williamr@4
    12
 * Copyright (c) 1999
williamr@4
    13
 * Boris Fomitchev
williamr@4
    14
 *
williamr@4
    15
 * This material is provided "as is", with absolutely no warranty expressed
williamr@4
    16
 * or implied. Any use is at your own risk.
williamr@4
    17
 *
williamr@4
    18
 * Permission to use or copy this software for any purpose is hereby granted
williamr@4
    19
 * without fee, provided the above notices are retained on all copies.
williamr@4
    20
 * Permission to modify the code and to distribute modified code is granted,
williamr@4
    21
 * provided the above notices are retained, and a notice that the code was
williamr@4
    22
 * modified is included with the above copyright notice.
williamr@4
    23
 *
williamr@4
    24
 */
williamr@4
    25
williamr@4
    26
/* NOTE: This is an internal header file, included by other STL headers.
williamr@4
    27
 *   You should not attempt to use it directly.
williamr@4
    28
 */
williamr@4
    29
williamr@4
    30
#ifndef _STLP_INTERNAL_ALGO_H
williamr@4
    31
#define _STLP_INTERNAL_ALGO_H
williamr@4
    32
williamr@4
    33
#ifndef _STLP_INTERNAL_ALGOBASE_H
williamr@4
    34
#  include <stl/_algobase.h>
williamr@4
    35
#endif
williamr@4
    36
williamr@4
    37
#ifndef _STLP_INTERNAL_HEAP_H
williamr@4
    38
#  include <stl/_heap.h>
williamr@4
    39
#endif
williamr@4
    40
williamr@4
    41
#ifndef _STLP_INTERNAL_ITERATOR_H
williamr@4
    42
#  include <stl/_iterator.h>
williamr@4
    43
#endif
williamr@4
    44
williamr@4
    45
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
williamr@4
    46
#  include <stl/_function_base.h>
williamr@4
    47
#endif
williamr@4
    48
williamr@4
    49
#if defined (__SUNPRO_CC) && !defined (_STLP_INTERNAL_CSTDIO)
williamr@4
    50
// remove() conflict
williamr@4
    51
#  include <stl/_cstdio.h>
williamr@4
    52
#endif
williamr@4
    53
williamr@4
    54
_STLP_BEGIN_NAMESPACE
williamr@4
    55
williamr@4
    56
// for_each.  Apply a function to every element of a range.
williamr@4
    57
template <class _InputIter, class _Function>
williamr@4
    58
_STLP_INLINE_LOOP _Function
williamr@4
    59
for_each(_InputIter __first, _InputIter __last, _Function __f) {
williamr@4
    60
  for ( ; __first != __last; ++__first)
williamr@4
    61
    __f(*__first);
williamr@4
    62
  return __f;
williamr@4
    63
}
williamr@4
    64
williamr@4
    65
// count_if
williamr@4
    66
template <class _InputIter, class _Predicate>
williamr@4
    67
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
williamr@4
    68
count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
williamr@4
    69
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
    70
  _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
williamr@4
    71
  for ( ; __first != __last; ++__first) {
williamr@4
    72
    if (__pred(*__first))
williamr@4
    73
      ++__n;
williamr@4
    74
  }
williamr@4
    75
  return __n;
williamr@4
    76
}
williamr@4
    77
williamr@4
    78
// adjacent_find.
williamr@4
    79
williamr@4
    80
template <class _ForwardIter, class _BinaryPredicate>
williamr@4
    81
_STLP_INLINE_LOOP _ForwardIter
williamr@4
    82
adjacent_find(_ForwardIter __first, _ForwardIter __last,
williamr@4
    83
              _BinaryPredicate __binary_pred) {
williamr@4
    84
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
    85
  if (__first == __last)
williamr@4
    86
    return __last;
williamr@4
    87
  _ForwardIter __next = __first;
williamr@4
    88
  while(++__next != __last) {
williamr@4
    89
    if (__binary_pred(*__first, *__next))
williamr@4
    90
      return __first;
williamr@4
    91
    __first = __next;
williamr@4
    92
  }
williamr@4
    93
  return __last;
williamr@4
    94
}
williamr@4
    95
williamr@4
    96
template <class _ForwardIter>
williamr@4
    97
_STLP_INLINE_LOOP _ForwardIter
williamr@4
    98
adjacent_find(_ForwardIter __first, _ForwardIter __last) {
williamr@4
    99
  return adjacent_find(__first, __last,
williamr@4
   100
                       _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
williamr@4
   101
}
williamr@4
   102
williamr@4
   103
#if !defined (_STLP_NO_ANACHRONISMS)
williamr@4
   104
template <class _InputIter, class _Tp, class _Size>
williamr@4
   105
_STLP_INLINE_LOOP void
williamr@4
   106
count(_InputIter __first, _InputIter __last, const _Tp& __val, _Size& __n) {
williamr@4
   107
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   108
    for ( ; __first != __last; ++__first)
williamr@4
   109
      if (*__first == __val)
williamr@4
   110
        ++__n;
williamr@4
   111
}
williamr@4
   112
williamr@4
   113
template <class _InputIter, class _Predicate, class _Size>
williamr@4
   114
_STLP_INLINE_LOOP void
williamr@4
   115
count_if(_InputIter __first, _InputIter __last, _Predicate __pred, _Size& __n) {
williamr@4
   116
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   117
  for ( ; __first != __last; ++__first)
williamr@4
   118
    if (__pred(*__first))
williamr@4
   119
      ++__n;
williamr@4
   120
}
williamr@4
   121
#endif
williamr@4
   122
williamr@4
   123
template <class _ForwardIter1, class _ForwardIter2>
williamr@4
   124
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
williamr@4
   125
                     _ForwardIter2 __first2, _ForwardIter2 __last2);
williamr@4
   126
williamr@4
   127
// search_n.  Search for __count consecutive copies of __val.
williamr@4
   128
template <class _ForwardIter, class _Integer, class _Tp>
williamr@4
   129
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
williamr@4
   130
                      _Integer __count, const _Tp& __val);
williamr@4
   131
template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
williamr@4
   132
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
williamr@4
   133
                      _Integer __count, const _Tp& __val, _BinaryPred __binary_pred);
williamr@4
   134
williamr@4
   135
template <class _InputIter, class _ForwardIter>
williamr@4
   136
inline _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
williamr@4
   137
                                _ForwardIter __first2, _ForwardIter __last2) {
williamr@4
   138
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
williamr@4
   139
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
williamr@4
   140
  return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2,
williamr@4
   141
                                    _STLP_PRIV __equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
williamr@4
   142
}
williamr@4
   143
williamr@4
   144
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
williamr@4
   145
inline _InputIter
williamr@4
   146
find_first_of(_InputIter __first1, _InputIter __last1,
williamr@4
   147
              _ForwardIter __first2, _ForwardIter __last2, _BinaryPredicate __comp) {
williamr@4
   148
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
williamr@4
   149
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first2, __last2))
williamr@4
   150
  return _STLP_PRIV __find_first_of(__first1, __last1, __first2, __last2, __comp);
williamr@4
   151
}
williamr@4
   152
williamr@4
   153
template <class _ForwardIter1, class _ForwardIter2>
williamr@4
   154
_ForwardIter1
williamr@4
   155
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
williamr@4
   156
         _ForwardIter2 __first2, _ForwardIter2 __last2);
williamr@4
   157
williamr@4
   158
// swap_ranges
williamr@4
   159
template <class _ForwardIter1, class _ForwardIter2>
williamr@4
   160
_STLP_INLINE_LOOP _ForwardIter2
williamr@4
   161
swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2) {
williamr@4
   162
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
williamr@4
   163
  for ( ; __first1 != __last1; ++__first1, ++__first2)
williamr@4
   164
    iter_swap(__first1, __first2);
williamr@4
   165
  return __first2;
williamr@4
   166
}
williamr@4
   167
williamr@4
   168
// transform
williamr@4
   169
template <class _InputIter, class _OutputIter, class _UnaryOperation>
williamr@4
   170
_STLP_INLINE_LOOP _OutputIter
williamr@4
   171
transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) {
williamr@4
   172
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   173
  for ( ; __first != __last; ++__first, ++__result)
williamr@4
   174
    *__result = __opr(*__first);
williamr@4
   175
  return __result;
williamr@4
   176
}
williamr@4
   177
template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
williamr@4
   178
_STLP_INLINE_LOOP _OutputIter
williamr@4
   179
transform(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   180
          _InputIter2 __first2, _OutputIter __result,_BinaryOperation __binary_op) {
williamr@4
   181
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first1, __last1))
williamr@4
   182
  for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
williamr@4
   183
    *__result = __binary_op(*__first1, *__first2);
williamr@4
   184
  return __result;
williamr@4
   185
}
williamr@4
   186
williamr@4
   187
// replace_if, replace_copy, replace_copy_if
williamr@4
   188
williamr@4
   189
template <class _ForwardIter, class _Predicate, class _Tp>
williamr@4
   190
_STLP_INLINE_LOOP void
williamr@4
   191
replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp& __new_value) {
williamr@4
   192
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   193
  for ( ; __first != __last; ++__first)
williamr@4
   194
    if (__pred(*__first))
williamr@4
   195
      *__first = __new_value;
williamr@4
   196
}
williamr@4
   197
williamr@4
   198
template <class _InputIter, class _OutputIter, class _Tp>
williamr@4
   199
_STLP_INLINE_LOOP  _OutputIter
williamr@4
   200
replace_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
williamr@4
   201
             const _Tp& __old_value, const _Tp& __new_value) {
williamr@4
   202
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   203
  for ( ; __first != __last; ++__first, ++__result)
williamr@4
   204
    *__result = *__first == __old_value ? __new_value : *__first;
williamr@4
   205
  return __result;
williamr@4
   206
}
williamr@4
   207
williamr@4
   208
template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
williamr@4
   209
_STLP_INLINE_LOOP _OutputIter
williamr@4
   210
replace_copy_if(_Iterator __first, _Iterator __last,
williamr@4
   211
                _OutputIter __result,
williamr@4
   212
                _Predicate __pred, const _Tp& __new_value) {
williamr@4
   213
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   214
  for ( ; __first != __last; ++__first, ++__result)
williamr@4
   215
    *__result = __pred(*__first) ? __new_value : *__first;
williamr@4
   216
  return __result;
williamr@4
   217
}
williamr@4
   218
williamr@4
   219
// generate and generate_n
williamr@4
   220
williamr@4
   221
template <class _ForwardIter, class _Generator>
williamr@4
   222
_STLP_INLINE_LOOP void
williamr@4
   223
generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
williamr@4
   224
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   225
  for ( ; __first != __last; ++__first)
williamr@4
   226
    *__first = __gen();
williamr@4
   227
}
williamr@4
   228
williamr@4
   229
template <class _OutputIter, class _Size, class _Generator>
williamr@4
   230
_STLP_INLINE_LOOP void
williamr@4
   231
generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
williamr@4
   232
  for ( ; __n > 0; --__n, ++__first)
williamr@4
   233
    *__first = __gen();
williamr@4
   234
}
williamr@4
   235
williamr@4
   236
// remove, remove_if, remove_copy, remove_copy_if
williamr@4
   237
williamr@4
   238
template <class _InputIter, class _OutputIter, class _Tp>
williamr@4
   239
_STLP_INLINE_LOOP _OutputIter
williamr@4
   240
remove_copy(_InputIter __first, _InputIter __last,_OutputIter __result, const _Tp& __val) {
williamr@4
   241
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   242
  for ( ; __first != __last; ++__first) {
williamr@4
   243
    if (!(*__first == __val)) {
williamr@4
   244
      *__result = *__first;
williamr@4
   245
      ++__result;
williamr@4
   246
    }
williamr@4
   247
  }
williamr@4
   248
  return __result;
williamr@4
   249
}
williamr@4
   250
williamr@4
   251
template <class _InputIter, class _OutputIter, class _Predicate>
williamr@4
   252
_STLP_INLINE_LOOP _OutputIter
williamr@4
   253
remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred) {
williamr@4
   254
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   255
  for ( ; __first != __last; ++__first) {
williamr@4
   256
    if (!__pred(*__first)) {
williamr@4
   257
      *__result = *__first;
williamr@4
   258
      ++__result;
williamr@4
   259
    }
williamr@4
   260
  }
williamr@4
   261
  return __result;
williamr@4
   262
}
williamr@4
   263
williamr@4
   264
template <class _ForwardIter, class _Tp>
williamr@4
   265
_STLP_INLINE_LOOP _ForwardIter
williamr@4
   266
remove(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
williamr@4
   267
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   268
  __first = find(__first, __last, __val);
williamr@4
   269
  if (__first == __last)
williamr@4
   270
    return __first;
williamr@4
   271
  else {
williamr@4
   272
    _ForwardIter __next = __first;
williamr@4
   273
    return remove_copy(++__next, __last, __first, __val);
williamr@4
   274
  }
williamr@4
   275
}
williamr@4
   276
williamr@4
   277
template <class _ForwardIter, class _Predicate>
williamr@4
   278
_STLP_INLINE_LOOP _ForwardIter
williamr@4
   279
remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred) {
williamr@4
   280
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   281
  __first = find_if(__first, __last, __pred);
williamr@4
   282
  if ( __first == __last )
williamr@4
   283
    return __first;
williamr@4
   284
  else {
williamr@4
   285
    _ForwardIter __next = __first;
williamr@4
   286
    return remove_copy_if(++__next, __last, __first, __pred);
williamr@4
   287
  }
williamr@4
   288
}
williamr@4
   289
williamr@4
   290
// unique and unique_copy
williamr@4
   291
template <class _InputIter, class _OutputIter>
williamr@4
   292
_OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
williamr@4
   293
williamr@4
   294
template <class _InputIter, class _OutputIter, class _BinaryPredicate>
williamr@4
   295
_OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
williamr@4
   296
                        _BinaryPredicate __binary_pred);
williamr@4
   297
williamr@4
   298
template <class _ForwardIter>
williamr@4
   299
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
williamr@4
   300
  __first = adjacent_find(__first, __last);
williamr@4
   301
  return unique_copy(__first, __last, __first);
williamr@4
   302
}
williamr@4
   303
williamr@4
   304
template <class _ForwardIter, class _BinaryPredicate>
williamr@4
   305
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
williamr@4
   306
                           _BinaryPredicate __binary_pred) {
williamr@4
   307
  __first = adjacent_find(__first, __last, __binary_pred);
williamr@4
   308
  return unique_copy(__first, __last, __first, __binary_pred);
williamr@4
   309
}
williamr@4
   310
williamr@4
   311
// reverse and reverse_copy, and their auxiliary functions
williamr@4
   312
williamr@4
   313
template <class _BidirectionalIter>
williamr@4
   314
_STLP_INLINE_LOOP void
williamr@4
   315
__reverse(_BidirectionalIter __first, _BidirectionalIter __last, const bidirectional_iterator_tag &) {
williamr@4
   316
  for (; __first != __last && __first != --__last; ++__first)
williamr@4
   317
    iter_swap(__first,__last);
williamr@4
   318
}
williamr@4
   319
williamr@4
   320
williamr@4
   321
template <class _RandomAccessIter>
williamr@4
   322
_STLP_INLINE_LOOP void
williamr@4
   323
__reverse(_RandomAccessIter __first, _RandomAccessIter __last, const random_access_iterator_tag &) {
williamr@4
   324
  for (; __first < __last; ++__first)
williamr@4
   325
    iter_swap(__first, --__last);
williamr@4
   326
}
williamr@4
   327
williamr@4
   328
template <class _BidirectionalIter>
williamr@4
   329
inline void
williamr@4
   330
reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
williamr@4
   331
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   332
  __reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
williamr@4
   333
}
williamr@4
   334
williamr@4
   335
template <class _BidirectionalIter, class _OutputIter>
williamr@4
   336
_STLP_INLINE_LOOP
williamr@4
   337
_OutputIter reverse_copy(_BidirectionalIter __first,
williamr@4
   338
                         _BidirectionalIter __last,
williamr@4
   339
                         _OutputIter __result) {
williamr@4
   340
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   341
  while (__first != __last) {
williamr@4
   342
    --__last;
williamr@4
   343
    *__result = *__last;
williamr@4
   344
    ++__result;
williamr@4
   345
  }
williamr@4
   346
  return __result;
williamr@4
   347
}
williamr@4
   348
williamr@4
   349
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   350
williamr@4
   351
// rotate and rotate_copy, and their auxiliary functions
williamr@4
   352
template <class _EuclideanRingElement>
williamr@4
   353
_STLP_INLINE_LOOP
williamr@4
   354
_EuclideanRingElement __gcd(_EuclideanRingElement __m,
williamr@4
   355
                            _EuclideanRingElement __n) {
williamr@4
   356
  while (__n != 0) {
williamr@4
   357
    _EuclideanRingElement __t = __m % __n;
williamr@4
   358
    __m = __n;
williamr@4
   359
    __n = __t;
williamr@4
   360
  }
williamr@4
   361
  return __m;
williamr@4
   362
}
williamr@4
   363
williamr@4
   364
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   365
williamr@4
   366
template <class _ForwardIter>
williamr@4
   367
void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
williamr@4
   368
williamr@4
   369
template <class _ForwardIter, class _OutputIter>
williamr@4
   370
inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
williamr@4
   371
                               _ForwardIter __last, _OutputIter __result) {
williamr@4
   372
  return copy(__first, __middle, copy(__middle, __last, __result));
williamr@4
   373
}
williamr@4
   374
williamr@4
   375
// random_shuffle
williamr@4
   376
williamr@4
   377
template <class _RandomAccessIter>
williamr@4
   378
void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
williamr@4
   379
williamr@4
   380
template <class _RandomAccessIter, class _RandomNumberGenerator>
williamr@4
   381
void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
williamr@4
   382
                    _RandomNumberGenerator& __rand);
williamr@4
   383
williamr@4
   384
#if !defined (_STLP_NO_EXTENSIONS)
williamr@4
   385
// random_sample and random_sample_n (extensions, not part of the standard).
williamr@4
   386
williamr@4
   387
template <class _ForwardIter, class _OutputIter, class _Distance>
williamr@4
   388
_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
williamr@4
   389
                            _OutputIter __out_ite, const _Distance __n);
williamr@4
   390
williamr@4
   391
template <class _ForwardIter, class _OutputIter, class _Distance,
williamr@4
   392
          class _RandomNumberGenerator>
williamr@4
   393
_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
williamr@4
   394
                            _OutputIter __out_ite, const _Distance __n,
williamr@4
   395
                            _RandomNumberGenerator& __rand);
williamr@4
   396
williamr@4
   397
template <class _InputIter, class _RandomAccessIter>
williamr@4
   398
_RandomAccessIter
williamr@4
   399
random_sample(_InputIter __first, _InputIter __last,
williamr@4
   400
              _RandomAccessIter __out_first, _RandomAccessIter __out_last);
williamr@4
   401
williamr@4
   402
template <class _InputIter, class _RandomAccessIter,
williamr@4
   403
          class _RandomNumberGenerator>
williamr@4
   404
_RandomAccessIter
williamr@4
   405
random_sample(_InputIter __first, _InputIter __last,
williamr@4
   406
              _RandomAccessIter __out_first, _RandomAccessIter __out_last,
williamr@4
   407
              _RandomNumberGenerator& __rand);
williamr@4
   408
williamr@4
   409
#endif /* _STLP_NO_EXTENSIONS */
williamr@4
   410
williamr@4
   411
// partition, stable_partition, and their auxiliary functions
williamr@4
   412
williamr@4
   413
template <class _ForwardIter, class _Predicate>
williamr@4
   414
_ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate   __pred);
williamr@4
   415
williamr@4
   416
template <class _ForwardIter, class _Predicate>
williamr@4
   417
_ForwardIter
williamr@4
   418
stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
williamr@4
   419
williamr@4
   420
// sort() and its auxiliary functions.
williamr@4
   421
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   422
williamr@4
   423
template <class _Size>
williamr@4
   424
inline _Size __lg(_Size __n) {
williamr@4
   425
  _Size __k;
williamr@4
   426
  for (__k = 0; __n != 1; __n >>= 1) ++__k;
williamr@4
   427
  return __k;
williamr@4
   428
}
williamr@4
   429
williamr@4
   430
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   431
williamr@4
   432
template <class _RandomAccessIter>
williamr@4
   433
void sort(_RandomAccessIter __first, _RandomAccessIter __last);
williamr@4
   434
template <class _RandomAccessIter, class _Compare>
williamr@4
   435
void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
williamr@4
   436
williamr@4
   437
// stable_sort() and its auxiliary functions.
williamr@4
   438
template <class _RandomAccessIter>
williamr@4
   439
void stable_sort(_RandomAccessIter __first,
williamr@4
   440
                 _RandomAccessIter __last);
williamr@4
   441
williamr@4
   442
template <class _RandomAccessIter, class _Compare>
williamr@4
   443
void stable_sort(_RandomAccessIter __first,
williamr@4
   444
                 _RandomAccessIter __last, _Compare __comp);
williamr@4
   445
williamr@4
   446
// partial_sort, partial_sort_copy, and auxiliary functions.
williamr@4
   447
williamr@4
   448
template <class _RandomAccessIter>
williamr@4
   449
void partial_sort(_RandomAccessIter __first, _RandomAccessIter __middle,
williamr@4
   450
                  _RandomAccessIter __last);
williamr@4
   451
williamr@4
   452
template <class _RandomAccessIter, class _Compare>
williamr@4
   453
void partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
williamr@4
   454
                  _RandomAccessIter __last, _Compare __comp);
williamr@4
   455
williamr@4
   456
template <class _InputIter, class _RandomAccessIter>
williamr@4
   457
_RandomAccessIter
williamr@4
   458
partial_sort_copy(_InputIter __first, _InputIter __last,
williamr@4
   459
                  _RandomAccessIter __result_first, _RandomAccessIter __result_last);
williamr@4
   460
williamr@4
   461
template <class _InputIter, class _RandomAccessIter, class _Compare>
williamr@4
   462
_RandomAccessIter
williamr@4
   463
partial_sort_copy(_InputIter __first, _InputIter __last,
williamr@4
   464
                  _RandomAccessIter __result_first,
williamr@4
   465
                  _RandomAccessIter __result_last, _Compare __comp);
williamr@4
   466
williamr@4
   467
// nth_element() and its auxiliary functions.
williamr@4
   468
template <class _RandomAccessIter>
williamr@4
   469
void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
williamr@4
   470
                 _RandomAccessIter __last);
williamr@4
   471
williamr@4
   472
template <class _RandomAccessIter, class _Compare>
williamr@4
   473
void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
williamr@4
   474
                 _RandomAccessIter __last, _Compare __comp);
williamr@4
   475
williamr@4
   476
// auxiliary class for lower_bound, etc.
williamr@4
   477
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   478
williamr@4
   479
template <class _T1, class _T2>
williamr@4
   480
struct __less_2 {
williamr@4
   481
  bool operator() (const _T1& __x, const _T2& __y) const { return __x < __y ; }
williamr@4
   482
};
williamr@4
   483
williamr@4
   484
template <class _T1, class _T2>
williamr@4
   485
__less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
williamr@4
   486
williamr@4
   487
#if defined (_STLP_FUNCTION_PARTIAL_ORDER)
williamr@4
   488
template <class _Tp>
williamr@4
   489
less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
williamr@4
   490
#endif
williamr@4
   491
williamr@4
   492
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   493
williamr@4
   494
// Binary search (lower_bound, upper_bound, equal_range, binary_search).
williamr@4
   495
template <class _ForwardIter, class _Tp>
williamr@4
   496
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
williamr@4
   497
                                   const _Tp& __val) {
williamr@4
   498
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   499
  return _STLP_PRIV __lower_bound(__first, __last, __val,
williamr@4
   500
                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
williamr@4
   501
                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
williamr@4
   502
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   503
}
williamr@4
   504
williamr@4
   505
template <class _ForwardIter, class _Tp, class _Compare>
williamr@4
   506
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
williamr@4
   507
                                const _Tp& __val, _Compare __comp) {
williamr@4
   508
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   509
  return _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
williamr@4
   510
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   511
}
williamr@4
   512
williamr@4
   513
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   514
williamr@4
   515
template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
williamr@4
   516
_ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
williamr@4
   517
                           _Compare1 __comp1, _Compare2 __comp2, _Distance*);
williamr@4
   518
williamr@4
   519
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   520
williamr@4
   521
template <class _ForwardIter, class _Tp>
williamr@4
   522
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
williamr@4
   523
                                const _Tp& __val) {
williamr@4
   524
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   525
  return _STLP_PRIV __upper_bound(__first, __last, __val,
williamr@4
   526
                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
williamr@4
   527
                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
williamr@4
   528
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   529
}
williamr@4
   530
williamr@4
   531
template <class _ForwardIter, class _Tp, class _Compare>
williamr@4
   532
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
williamr@4
   533
                                const _Tp& __val, _Compare __comp) {
williamr@4
   534
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   535
  return _STLP_PRIV __upper_bound(__first, __last, __val, __comp, __comp,
williamr@4
   536
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   537
}
williamr@4
   538
williamr@4
   539
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   540
williamr@4
   541
template <class _ForwardIter, class _Tp, class _Compare1, class _Compare2, class _Distance>
williamr@4
   542
pair<_ForwardIter, _ForwardIter>
williamr@4
   543
__equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
williamr@4
   544
              _Compare1 __comp1, _Compare2 __comp2, _Distance*);
williamr@4
   545
williamr@4
   546
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   547
williamr@4
   548
template <class _ForwardIter, class _Tp>
williamr@4
   549
inline pair<_ForwardIter, _ForwardIter>
williamr@4
   550
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
williamr@4
   551
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   552
  return _STLP_PRIV __equal_range(__first, __last, __val,
williamr@4
   553
                                  _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
williamr@4
   554
                                  _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
williamr@4
   555
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   556
}
williamr@4
   557
williamr@4
   558
template <class _ForwardIter, class _Tp, class _Compare>
williamr@4
   559
inline pair<_ForwardIter, _ForwardIter>
williamr@4
   560
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
williamr@4
   561
            _Compare __comp) {
williamr@4
   562
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   563
  return _STLP_PRIV __equal_range(__first, __last, __val, __comp, __comp,
williamr@4
   564
                                  _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   565
}
williamr@4
   566
williamr@4
   567
template <class _ForwardIter, class _Tp>
williamr@4
   568
inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
williamr@4
   569
                   const _Tp& __val) {
williamr@4
   570
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   571
  _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val,
williamr@4
   572
                                              _STLP_PRIV __less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
williamr@4
   573
                                              _STLP_PRIV __less2((_Tp*)0, _STLP_VALUE_TYPE(__first, _ForwardIter)),
williamr@4
   574
                                              _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   575
  return __i != __last && !(__val < *__i);
williamr@4
   576
}
williamr@4
   577
williamr@4
   578
template <class _ForwardIter, class _Tp, class _Compare>
williamr@4
   579
inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
williamr@4
   580
                          const _Tp& __val,
williamr@4
   581
                          _Compare __comp) {
williamr@4
   582
  _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
williamr@4
   583
  _ForwardIter __i = _STLP_PRIV __lower_bound(__first, __last, __val, __comp, __comp,
williamr@4
   584
                                              _STLP_DISTANCE_TYPE(__first, _ForwardIter));
williamr@4
   585
  return __i != __last && !__comp(__val, *__i);
williamr@4
   586
}
williamr@4
   587
williamr@4
   588
// merge, with and without an explicitly supplied comparison function.
williamr@4
   589
williamr@4
   590
template <class _InputIter1, class _InputIter2, class _OutputIter>
williamr@4
   591
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   592
                  _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   593
                  _OutputIter __result);
williamr@4
   594
williamr@4
   595
template <class _InputIter1, class _InputIter2, class _OutputIter,
williamr@4
   596
          class _Compare>
williamr@4
   597
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   598
                  _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   599
                  _OutputIter __result, _Compare __comp);
williamr@4
   600
williamr@4
   601
williamr@4
   602
// inplace_merge and its auxiliary functions.
williamr@4
   603
williamr@4
   604
williamr@4
   605
template <class _BidirectionalIter>
williamr@4
   606
void inplace_merge(_BidirectionalIter __first,
williamr@4
   607
                   _BidirectionalIter __middle,
williamr@4
   608
                   _BidirectionalIter __last) ;
williamr@4
   609
williamr@4
   610
template <class _BidirectionalIter, class _Compare>
williamr@4
   611
void inplace_merge(_BidirectionalIter __first,
williamr@4
   612
                   _BidirectionalIter __middle,
williamr@4
   613
                   _BidirectionalIter __last, _Compare __comp);
williamr@4
   614
williamr@4
   615
// Set algorithms: includes, set_union, set_intersection, set_difference,
williamr@4
   616
// set_symmetric_difference.  All of these algorithms have the precondition
williamr@4
   617
// that their input ranges are sorted and the postcondition that their output
williamr@4
   618
// ranges are sorted.
williamr@4
   619
williamr@4
   620
template <class _InputIter1, class _InputIter2>
williamr@4
   621
bool includes(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   622
              _InputIter2 __first2, _InputIter2 __last2);
williamr@4
   623
williamr@4
   624
template <class _InputIter1, class _InputIter2, class _Compare>
williamr@4
   625
bool includes(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   626
              _InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
williamr@4
   627
williamr@4
   628
template <class _InputIter1, class _InputIter2, class _OutputIter>
williamr@4
   629
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   630
                      _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   631
                      _OutputIter __result);
williamr@4
   632
williamr@4
   633
template <class _InputIter1, class _InputIter2, class _OutputIter,
williamr@4
   634
          class _Compare>
williamr@4
   635
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   636
                      _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   637
                      _OutputIter __result, _Compare __comp);
williamr@4
   638
williamr@4
   639
template <class _InputIter1, class _InputIter2, class _OutputIter>
williamr@4
   640
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   641
                             _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   642
                             _OutputIter __result);
williamr@4
   643
williamr@4
   644
template <class _InputIter1, class _InputIter2, class _OutputIter,
williamr@4
   645
          class _Compare>
williamr@4
   646
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   647
                             _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   648
                             _OutputIter __result, _Compare __comp);
williamr@4
   649
williamr@4
   650
williamr@4
   651
williamr@4
   652
template <class _InputIter1, class _InputIter2, class _OutputIter>
williamr@4
   653
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   654
                           _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   655
                           _OutputIter __result);
williamr@4
   656
williamr@4
   657
template <class _InputIter1, class _InputIter2, class _OutputIter,
williamr@4
   658
          class _Compare>
williamr@4
   659
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   660
                           _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   661
                           _OutputIter __result, _Compare __comp);
williamr@4
   662
williamr@4
   663
template <class _InputIter1, class _InputIter2, class _OutputIter>
williamr@4
   664
_OutputIter
williamr@4
   665
set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   666
                         _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   667
                         _OutputIter __result);
williamr@4
   668
williamr@4
   669
williamr@4
   670
template <class _InputIter1, class _InputIter2, class _OutputIter,
williamr@4
   671
          class _Compare>
williamr@4
   672
_OutputIter
williamr@4
   673
set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
williamr@4
   674
                         _InputIter2 __first2, _InputIter2 __last2,
williamr@4
   675
                         _OutputIter __result,
williamr@4
   676
                         _Compare __comp);
williamr@4
   677
williamr@4
   678
williamr@4
   679
// min_element and max_element, with and without an explicitly supplied
williamr@4
   680
// comparison function.
williamr@4
   681
williamr@4
   682
template <class _ForwardIter>
williamr@4
   683
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
williamr@4
   684
template <class _ForwardIter, class _Compare>
williamr@4
   685
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
williamr@4
   686
                            _Compare __comp);
williamr@4
   687
williamr@4
   688
template <class _ForwardIter>
williamr@4
   689
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
williamr@4
   690
williamr@4
   691
template <class _ForwardIter, class _Compare>
williamr@4
   692
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
williamr@4
   693
                            _Compare __comp);
williamr@4
   694
williamr@4
   695
// next_permutation and prev_permutation, with and without an explicitly
williamr@4
   696
// supplied comparison function.
williamr@4
   697
williamr@4
   698
template <class _BidirectionalIter>
williamr@4
   699
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
williamr@4
   700
williamr@4
   701
template <class _BidirectionalIter, class _Compare>
williamr@4
   702
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
williamr@4
   703
                      _Compare __comp);
williamr@4
   704
williamr@4
   705
williamr@4
   706
template <class _BidirectionalIter>
williamr@4
   707
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
williamr@4
   708
williamr@4
   709
williamr@4
   710
template <class _BidirectionalIter, class _Compare>
williamr@4
   711
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
williamr@4
   712
                      _Compare __comp);
williamr@4
   713
williamr@4
   714
#if !defined (_STLP_NO_EXTENSIONS)
williamr@4
   715
// is_heap, a predicate testing whether or not a range is
williamr@4
   716
// a heap.  This function is an extension, not part of the C++
williamr@4
   717
// standard.
williamr@4
   718
williamr@4
   719
template <class _RandomAccessIter>
williamr@4
   720
bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
williamr@4
   721
williamr@4
   722
template <class _RandomAccessIter, class _StrictWeakOrdering>
williamr@4
   723
bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
williamr@4
   724
             _StrictWeakOrdering __comp);
williamr@4
   725
williamr@4
   726
// is_sorted, a predicated testing whether a range is sorted in
williamr@4
   727
// nondescending order.  This is an extension, not part of the C++
williamr@4
   728
// standard.
williamr@4
   729
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@4
   730
williamr@4
   731
template <class _ForwardIter, class _StrictWeakOrdering>
williamr@4
   732
bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
williamr@4
   733
                 _StrictWeakOrdering __comp);
williamr@4
   734
williamr@4
   735
_STLP_MOVE_TO_STD_NAMESPACE
williamr@4
   736
template <class _ForwardIter>
williamr@4
   737
inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
williamr@4
   738
  return _STLP_PRIV __is_sorted(__first, __last,
williamr@4
   739
                                _STLP_PRIV __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
williamr@4
   740
}
williamr@4
   741
williamr@4
   742
template <class _ForwardIter, class _StrictWeakOrdering>
williamr@4
   743
inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
williamr@4
   744
                      _StrictWeakOrdering __comp) {
williamr@4
   745
  return _STLP_PRIV __is_sorted(__first, __last, __comp);
williamr@4
   746
}
williamr@4
   747
#endif
williamr@4
   748
williamr@4
   749
_STLP_END_NAMESPACE
williamr@4
   750
williamr@4
   751
#if !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@4
   752
#  include <stl/_algo.c>
williamr@4
   753
#endif
williamr@4
   754
williamr@4
   755
#endif /* _STLP_INTERNAL_ALGO_H */
williamr@4
   756
williamr@4
   757
// Local Variables:
williamr@4
   758
// mode:C++
williamr@4
   759
// End:
williamr@4
   760