epoc32/include/stdapis/stlportv5/stl/_algobase.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_algobase.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/*
williamr@2
     2
 *
williamr@2
     3
 * Copyright (c) 1994
williamr@2
     4
 * Hewlett-Packard Company
williamr@2
     5
 *
williamr@2
     6
 * Copyright (c) 1996,1997
williamr@2
     7
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     8
 *
williamr@2
     9
 * Copyright (c) 1997
williamr@2
    10
 * Moscow Center for SPARC Technology
williamr@2
    11
 *
williamr@2
    12
 * Copyright (c) 1999 
williamr@2
    13
 * Boris Fomitchev
williamr@2
    14
 *
williamr@2
    15
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
    16
 * or implied. Any use is at your own risk.
williamr@2
    17
 *
williamr@2
    18
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@2
    19
 * without fee, provided the above notices are retained on all copies.
williamr@2
    20
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    21
 * provided the above notices are retained, and a notice that the code was
williamr@2
    22
 * modified is included with the above copyright notice.
williamr@2
    23
 *
williamr@2
    24
 */
williamr@2
    25
williamr@2
    26
/* NOTE: This is an internal header file, included by other STL headers.
williamr@2
    27
 *   You should not attempt to use it directly.
williamr@2
    28
 */
williamr@2
    29
williamr@2
    30
williamr@2
    31
#ifndef _STLP_INTERNAL_ALGOBASE_H
williamr@2
    32
#define _STLP_INTERNAL_ALGOBASE_H
williamr@2
    33
williamr@2
    34
# if ! defined (_STLP_CSTDDEF)
williamr@2
    35
#  include <cstddef>
williamr@2
    36
# endif
williamr@2
    37
williamr@2
    38
#ifndef _STLP_CSTRING
williamr@2
    39
# include <cstring>
williamr@2
    40
#endif
williamr@2
    41
williamr@2
    42
#ifndef _STLP_CLIMITS
williamr@2
    43
# include <climits>
williamr@2
    44
#endif
williamr@2
    45
williamr@2
    46
# if ! defined (_STLP_CSTDLIB)
williamr@2
    47
#  include <cstdlib>
williamr@2
    48
# endif
williamr@2
    49
williamr@2
    50
# ifndef _STLP_INTERNAL_PAIR_H
williamr@2
    51
#  include <stl/_pair.h>
williamr@2
    52
# endif
williamr@2
    53
williamr@2
    54
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
williamr@2
    55
# include <stl/_iterator_base.h>
williamr@2
    56
#endif
williamr@2
    57
williamr@2
    58
_STLP_BEGIN_NAMESPACE
williamr@2
    59
// swap and iter_swap
williamr@2
    60
template <class _Tp>
williamr@2
    61
inline void swap(_Tp& __a, _Tp& __b) {
williamr@2
    62
  _Tp __tmp = __a;
williamr@2
    63
  __a = __b;
williamr@2
    64
  __b = __tmp;
williamr@2
    65
}
williamr@2
    66
williamr@2
    67
template <class _ForwardIter1, class _ForwardIter2>
williamr@2
    68
inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
williamr@2
    69
  swap(*__i1, *__i2);
williamr@2
    70
}
williamr@2
    71
williamr@2
    72
//--------------------------------------------------
williamr@2
    73
// min and max
williamr@2
    74
williamr@2
    75
# if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
williamr@2
    76
template <class _Tp>
williamr@2
    77
inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
williamr@2
    78
template <class _Tp>
williamr@2
    79
inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) {  return  __a < __b ? __b : __a; }
williamr@2
    80
#endif /* __BORLANDC__ */
williamr@2
    81
williamr@2
    82
# if defined (__BORLANDC__) && ( __BORLANDC__ < 0x530 || defined (_STLP_USE_OWN_NAMESPACE))
williamr@2
    83
inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
williamr@2
    84
inline unsigned long (max) (unsigned long __a, unsigned long __b) {  return  __a < __b ? __b : __a; }
williamr@2
    85
# endif
williamr@2
    86
williamr@2
    87
template <class _Tp, class _Compare>
williamr@2
    88
inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) { 
williamr@2
    89
  return __comp(__b, __a) ? __b : __a;
williamr@2
    90
}
williamr@2
    91
williamr@2
    92
template <class _Tp, class _Compare>
williamr@2
    93
inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
williamr@2
    94
  return __comp(__a, __b) ? __b : __a;
williamr@2
    95
}
williamr@2
    96
williamr@2
    97
//--------------------------------------------------
williamr@2
    98
// copy
williamr@2
    99
williamr@2
   100
// All of these auxiliary functions serve two purposes.  (1) Replace
williamr@2
   101
// calls to copy with memmove whenever possible.  (Memmove, not memcpy,
williamr@2
   102
// because the input and output ranges are permitted to overlap.)
williamr@2
   103
// (2) If we're using random access iterators, then write the loop as
williamr@2
   104
// a for loop with an explicit count.
williamr@2
   105
williamr@2
   106
template <class _InputIter, class _OutputIter, class _Distance>
williamr@2
   107
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
williamr@2
   108
                          _OutputIter __result,
williamr@2
   109
                          const input_iterator_tag &, _Distance*) {
williamr@2
   110
  for ( ; __first != __last; ++__result, ++__first)
williamr@2
   111
    *__result = *__first;
williamr@2
   112
  return __result;
williamr@2
   113
}
williamr@2
   114
williamr@2
   115
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG) 
williamr@2
   116
template <class _InputIter, class _OutputIter, class _Distance>
williamr@2
   117
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
williamr@2
   118
			  _OutputIter __result, const forward_iterator_tag &, _Distance* ) {
williamr@2
   119
  for ( ; __first != __last; ++__result, ++__first)
williamr@2
   120
    *__result = *__first;
williamr@2
   121
  return __result;
williamr@2
   122
}
williamr@2
   123
williamr@2
   124
williamr@2
   125
template <class _InputIter, class _OutputIter, class _Distance>
williamr@2
   126
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
williamr@2
   127
			  _OutputIter __result, const bidirectional_iterator_tag &, _Distance* __dis) {
williamr@2
   128
  for ( ; __first != __last; ++__result, ++__first)
williamr@2
   129
    *__result = *__first;
williamr@2
   130
  return __result;
williamr@2
   131
}
williamr@2
   132
# endif 
williamr@2
   133
williamr@2
   134
template <class _RandomAccessIter, class _OutputIter, class _Distance>
williamr@2
   135
inline _OutputIter
williamr@2
   136
__copy(_RandomAccessIter __first, _RandomAccessIter __last,
williamr@2
   137
       _OutputIter __result, const random_access_iterator_tag &, _Distance*) {
williamr@2
   138
  for (_Distance __n = __last - __first; __n > 0; --__n) {
williamr@2
   139
    *__result = *__first;
williamr@2
   140
    ++__first;
williamr@2
   141
    ++__result;
williamr@2
   142
  }
williamr@2
   143
  return __result;
williamr@2
   144
}
williamr@2
   145
williamr@2
   146
inline void*
williamr@2
   147
__copy_trivial(const void* __first, const void* __last, void* __result) {
williamr@2
   148
  return (__last == __first) ? __result : 
williamr@2
   149
    ((char*)memmove(__result, __first, ((const char*)__last - (const char*)__first))) + 
williamr@2
   150
    ((const char*)__last - (const char*)__first);
williamr@2
   151
}
williamr@2
   152
williamr@2
   153
//--------------------------------------------------
williamr@2
   154
// copy_backward auxiliary functions
williamr@2
   155
williamr@2
   156
template <class _BidirectionalIter1, class _BidirectionalIter2, 
williamr@2
   157
          class _Distance>
williamr@2
   158
inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first, 
williamr@2
   159
                                           _BidirectionalIter1 __last, 
williamr@2
   160
                                           _BidirectionalIter2 __result,
williamr@2
   161
                                           const bidirectional_iterator_tag &,
williamr@2
   162
                                           _Distance*) 
williamr@2
   163
{
williamr@2
   164
  while (__first != __last)
williamr@2
   165
    *--__result = *--__last;
williamr@2
   166
  return __result;
williamr@2
   167
}
williamr@2
   168
williamr@2
   169
template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
williamr@2
   170
inline _BidirectionalIter __copy_backward(_RandomAccessIter __first, 
williamr@2
   171
                                          _RandomAccessIter __last, 
williamr@2
   172
                                          _BidirectionalIter __result,
williamr@2
   173
                                          const random_access_iterator_tag &,
williamr@2
   174
                                          _Distance*)
williamr@2
   175
{
williamr@2
   176
  for (_Distance __n = __last - __first; __n > 0; --__n)
williamr@2
   177
    *--__result = *--__last;
williamr@2
   178
  return __result;
williamr@2
   179
}
williamr@2
   180
williamr@2
   181
inline void*
williamr@2
   182
__copy_trivial_backward(const void* __first, const void* __last, void* __result) {
williamr@2
   183
  const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
williamr@2
   184
  return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
williamr@2
   185
}
williamr@2
   186
williamr@2
   187
template <class _InputIter, class _OutputIter>
williamr@2
   188
inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
williamr@2
   189
  return __copy(__first, __last, __result, 
williamr@2
   190
                _STLP_ITERATOR_CATEGORY(__first, _InputIter), 
williamr@2
   191
                _STLP_DISTANCE_TYPE(__first, _InputIter));
williamr@2
   192
}
williamr@2
   193
template <class _InputIter, class _OutputIter>
williamr@2
   194
inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
williamr@2
   195
// we know they all pointers, so this cast is OK 
williamr@2
   196
  //  return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
williamr@2
   197
  return (_OutputIter)__copy_trivial(__first, __last, __result);
williamr@2
   198
}
williamr@2
   199
williamr@2
   200
template <class _InputIter, class _OutputIter>
williamr@2
   201
inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
williamr@2
   202
  return __copy_ptrs(__first, __last, __result, 
williamr@2
   203
                     _IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter), 
williamr@2
   204
                                   _STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
williamr@2
   205
}
williamr@2
   206
williamr@2
   207
template <class _InputIter, class _OutputIter>
williamr@2
   208
inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
williamr@2
   209
  return __copy(__first, __last, __result, 
williamr@2
   210
		_STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
williamr@2
   211
}
williamr@2
   212
williamr@2
   213
template <class _InputIter, class _OutputIter>
williamr@2
   214
inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
williamr@2
   215
  _STLP_DEBUG_CHECK(__check_range(__first, __last))
williamr@2
   216
    return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret());
williamr@2
   217
}
williamr@2
   218
williamr@2
   219
template <class _InputIter, class _OutputIter>
williamr@2
   220
inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
williamr@2
   221
  return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
williamr@2
   222
}
williamr@2
   223
template <class _InputIter, class _OutputIter>
williamr@2
   224
inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
williamr@2
   225
  return (_OutputIter)__copy_trivial_backward(__first, __last, __result);  
williamr@2
   226
}
williamr@2
   227
williamr@2
   228
template <class _InputIter, class _OutputIter>
williamr@2
   229
inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
williamr@2
   230
  return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first,_InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
williamr@2
   231
}
williamr@2
   232
williamr@2
   233
template <class _InputIter, class _OutputIter>
williamr@2
   234
inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
williamr@2
   235
  return __copy_backward_ptrs(__first, __last, __result,  
williamr@2
   236
                              _IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter), 
williamr@2
   237
                                            _STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
williamr@2
   238
}
williamr@2
   239
williamr@2
   240
template <class _InputIter, class _OutputIter>
williamr@2
   241
inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
williamr@2
   242
  _STLP_DEBUG_CHECK(__check_range(__first, __last))
williamr@2
   243
    return __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret() );
williamr@2
   244
}
williamr@2
   245
williamr@2
   246
#if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined ( _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS )
williamr@2
   247
#define _STLP_DECLARE_COPY_TRIVIAL(_Tp)                                \
williamr@2
   248
inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \
williamr@2
   249
{ return (_Tp*)__copy_trivial(__first, __last, __result); } \
williamr@2
   250
inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
williamr@2
   251
{ return (_Tp*)__copy_trivial_backward(__first, __last, __result); }
williamr@2
   252
williamr@2
   253
_STLP_DECLARE_COPY_TRIVIAL(char)
williamr@2
   254
# ifndef _STLP_NO_SIGNED_BUILTINS
williamr@2
   255
_STLP_DECLARE_COPY_TRIVIAL(signed char)
williamr@2
   256
# endif
williamr@2
   257
_STLP_DECLARE_COPY_TRIVIAL(unsigned char)
williamr@2
   258
_STLP_DECLARE_COPY_TRIVIAL(short)
williamr@2
   259
_STLP_DECLARE_COPY_TRIVIAL(unsigned short)
williamr@2
   260
_STLP_DECLARE_COPY_TRIVIAL(int)
williamr@2
   261
_STLP_DECLARE_COPY_TRIVIAL(unsigned int)
williamr@2
   262
_STLP_DECLARE_COPY_TRIVIAL(long)
williamr@2
   263
_STLP_DECLARE_COPY_TRIVIAL(unsigned long)
williamr@2
   264
#if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT) 
williamr@2
   265
_STLP_DECLARE_COPY_TRIVIAL(wchar_t)
williamr@2
   266
#endif
williamr@2
   267
#ifdef _STLP_LONG_LONG
williamr@2
   268
_STLP_DECLARE_COPY_TRIVIAL(long long)
williamr@2
   269
_STLP_DECLARE_COPY_TRIVIAL(unsigned long long)
williamr@2
   270
#endif 
williamr@2
   271
_STLP_DECLARE_COPY_TRIVIAL(float)
williamr@2
   272
_STLP_DECLARE_COPY_TRIVIAL(double)
williamr@2
   273
# ifndef _STLP_NO_LONG_DOUBLE
williamr@2
   274
_STLP_DECLARE_COPY_TRIVIAL(long double)
williamr@2
   275
# endif
williamr@2
   276
#undef _STLP_DECLARE_COPY_TRIVIAL
williamr@2
   277
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
williamr@2
   278
williamr@2
   279
//--------------------------------------------------
williamr@2
   280
// copy_n (not part of the C++ standard)
williamr@2
   281
williamr@2
   282
template <class _InputIter, class _Size, class _OutputIter>
williamr@2
   283
_STLP_INLINE_LOOP 
williamr@2
   284
pair<_InputIter, _OutputIter> __copy_n(_InputIter __first, _Size __count,
williamr@2
   285
                                       _OutputIter __result,
williamr@2
   286
                                       const input_iterator_tag &) {
williamr@2
   287
  for ( ; __count > 0; --__count) {
williamr@2
   288
    *__result = *__first;
williamr@2
   289
    ++__first;
williamr@2
   290
    ++__result;
williamr@2
   291
  }
williamr@2
   292
  return pair<_InputIter, _OutputIter>(__first, __result);
williamr@2
   293
}
williamr@2
   294
williamr@2
   295
template <class _RAIter, class _Size, class _OutputIter>
williamr@2
   296
inline pair<_RAIter, _OutputIter>
williamr@2
   297
__copy_n(_RAIter __first, _Size __count,
williamr@2
   298
         _OutputIter __result,
williamr@2
   299
         const random_access_iterator_tag &) {
williamr@2
   300
  _RAIter __last = __first + __count;
williamr@2
   301
  return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
williamr@2
   302
}
williamr@2
   303
williamr@2
   304
template <class _InputIter, class _Size, class _OutputIter>
williamr@2
   305
inline pair<_InputIter, _OutputIter>
williamr@2
   306
__copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
williamr@2
   307
  _STLP_FIX_LITERAL_BUG(__first)
williamr@2
   308
  return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
williamr@2
   309
}
williamr@2
   310
williamr@2
   311
template <class _InputIter, class _Size, class _OutputIter>
williamr@2
   312
inline pair<_InputIter, _OutputIter>
williamr@2
   313
copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
williamr@2
   314
  _STLP_FIX_LITERAL_BUG(__first)
williamr@2
   315
  return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
williamr@2
   316
}
williamr@2
   317
williamr@2
   318
//--------------------------------------------------
williamr@2
   319
// fill and fill_n
williamr@2
   320
williamr@2
   321
williamr@2
   322
template <class _ForwardIter, class _Tp>
williamr@2
   323
_STLP_INLINE_LOOP
williamr@2
   324
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
williamr@2
   325
  _STLP_DEBUG_CHECK(__check_range(__first, __last))
williamr@2
   326
  for ( ; __first != __last; ++__first)
williamr@2
   327
    *__first = __val;
williamr@2
   328
}
williamr@2
   329
williamr@2
   330
template <class _OutputIter, class _Size, class _Tp>
williamr@2
   331
_STLP_INLINE_LOOP
williamr@2
   332
_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
williamr@2
   333
  _STLP_FIX_LITERAL_BUG(__first)
williamr@2
   334
  for ( ; __n > 0; --__n, ++__first)
williamr@2
   335
    *__first = __val;
williamr@2
   336
  return __first;
williamr@2
   337
}
williamr@2
   338
williamr@2
   339
williamr@2
   340
// Specialization: for one-byte types we can use memset.
williamr@2
   341
williamr@2
   342
inline void fill(unsigned char* __first, unsigned char* __last,
williamr@2
   343
                 const unsigned char& __val) {
williamr@2
   344
  unsigned char __tmp = __val;
williamr@2
   345
  memset(__first, __tmp, __last - __first);
williamr@2
   346
}
williamr@2
   347
# ifndef _STLP_NO_SIGNED_BUILTINS
williamr@2
   348
inline void fill(signed char* __first, signed char* __last,
williamr@2
   349
                 const signed char& __val) {
williamr@2
   350
  signed char __tmp = __val;
williamr@2
   351
  memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
williamr@2
   352
}
williamr@2
   353
# endif
williamr@2
   354
inline void fill(char* __first, char* __last, const char& __val) {
williamr@2
   355
  char __tmp = __val;
williamr@2
   356
  memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
williamr@2
   357
}
williamr@2
   358
williamr@2
   359
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
williamr@2
   360
williamr@2
   361
template <class _Size>
williamr@2
   362
inline unsigned char* fill_n(unsigned char* __first, _Size __n,
williamr@2
   363
                             const unsigned char& __val) {
williamr@2
   364
  fill(__first, __first + __n, __val);
williamr@2
   365
  return __first + __n;
williamr@2
   366
}
williamr@2
   367
williamr@2
   368
template <class _Size>
williamr@2
   369
inline signed char* fill_n(char* __first, _Size __n,
williamr@2
   370
                           const signed char& __val) {
williamr@2
   371
  fill(__first, __first + __n, __val);
williamr@2
   372
  return __first + __n;
williamr@2
   373
}
williamr@2
   374
williamr@2
   375
template <class _Size>
williamr@2
   376
inline char* fill_n(char* __first, _Size __n, const char& __val) {
williamr@2
   377
  fill(__first, __first + __n, __val);
williamr@2
   378
  return __first + __n;
williamr@2
   379
}
williamr@2
   380
williamr@2
   381
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
williamr@2
   382
williamr@2
   383
williamr@2
   384
//--------------------------------------------------
williamr@2
   385
// equal and mismatch
williamr@2
   386
williamr@2
   387
template <class _InputIter1, class _InputIter2>
williamr@2
   388
_STLP_INLINE_LOOP
williamr@2
   389
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
williamr@2
   390
                                        _InputIter1 __last1,
williamr@2
   391
                                        _InputIter2 __first2) {
williamr@2
   392
  _STLP_FIX_LITERAL_BUG(__first2)
williamr@2
   393
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
williamr@2
   394
  while (__first1 != __last1 && *__first1 == *__first2) {
williamr@2
   395
    ++__first1;
williamr@2
   396
    ++__first2;
williamr@2
   397
  }
williamr@2
   398
  return pair<_InputIter1, _InputIter2>(__first1, __first2);
williamr@2
   399
}
williamr@2
   400
williamr@2
   401
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
williamr@2
   402
_STLP_INLINE_LOOP
williamr@2
   403
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
williamr@2
   404
                                        _InputIter1 __last1,
williamr@2
   405
                                        _InputIter2 __first2,
williamr@2
   406
                                        _BinaryPredicate __binary_pred) {
williamr@2
   407
  _STLP_FIX_LITERAL_BUG(__first2)
williamr@2
   408
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
williamr@2
   409
  while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
williamr@2
   410
    ++__first1;
williamr@2
   411
    ++__first2;
williamr@2
   412
  }
williamr@2
   413
  return pair<_InputIter1, _InputIter2>(__first1, __first2);
williamr@2
   414
}
williamr@2
   415
williamr@2
   416
template <class _InputIter1, class _InputIter2>
williamr@2
   417
_STLP_INLINE_LOOP
williamr@2
   418
bool equal(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   419
                  _InputIter2 __first2) {
williamr@2
   420
  _STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1)  _STLP_FIX_LITERAL_BUG(__first2)
williamr@2
   421
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
williamr@2
   422
  for ( ; __first1 != __last1; ++__first1, ++__first2)
williamr@2
   423
    if (!(*__first1 == *__first2))
williamr@2
   424
      return false;
williamr@2
   425
  return true;
williamr@2
   426
}
williamr@2
   427
williamr@2
   428
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
williamr@2
   429
_STLP_INLINE_LOOP
williamr@2
   430
bool equal(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   431
                  _InputIter2 __first2, _BinaryPredicate __binary_pred) {
williamr@2
   432
  _STLP_FIX_LITERAL_BUG(__first2)
williamr@2
   433
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
williamr@2
   434
  for ( ; __first1 != __last1; ++__first1, ++__first2)
williamr@2
   435
    if (!__binary_pred(*__first1, *__first2))
williamr@2
   436
      return false;
williamr@2
   437
  return true;
williamr@2
   438
}
williamr@2
   439
williamr@2
   440
//--------------------------------------------------
williamr@2
   441
// lexicographical_compare and lexicographical_compare_3way.
williamr@2
   442
// (the latter is not part of the C++ standard.)
williamr@2
   443
williamr@2
   444
template <class _InputIter1, class _InputIter2>
williamr@2
   445
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   446
                             _InputIter2 __first2, _InputIter2 __last2);
williamr@2
   447
williamr@2
   448
template <class _InputIter1, class _InputIter2, class _Compare>
williamr@2
   449
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   450
                             _InputIter2 __first2, _InputIter2 __last2,
williamr@2
   451
                             _Compare __comp);
williamr@2
   452
williamr@2
   453
inline bool 
williamr@2
   454
lexicographical_compare(const unsigned char* __first1,
williamr@2
   455
                        const unsigned char* __last1,
williamr@2
   456
                        const unsigned char* __first2,
williamr@2
   457
                        const unsigned char* __last2)
williamr@2
   458
{
williamr@2
   459
  const size_t __len1 = __last1 - __first1;
williamr@2
   460
  const size_t __len2 = __last2 - __first2;
williamr@2
   461
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1))
williamr@2
   462
  _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
williamr@2
   463
williamr@2
   464
  const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
williamr@2
   465
  return __result != 0 ? (__result < 0) : (__len1 < __len2);
williamr@2
   466
}
williamr@2
   467
williamr@2
   468
williamr@2
   469
# if !(CHAR_MAX == SCHAR_MAX)
williamr@2
   470
inline bool lexicographical_compare(const char* __first1, const char* __last1,
williamr@2
   471
                                    const char* __first2, const char* __last2)
williamr@2
   472
{
williamr@2
   473
  _STLP_DEBUG_CHECK(__check_range(__first1, __last1)) 
williamr@2
   474
  _STLP_DEBUG_CHECK(__check_range(__first2, __last2))
williamr@2
   475
williamr@2
   476
  return lexicographical_compare((const unsigned char*) __first1,
williamr@2
   477
                                 (const unsigned char*) __last1,
williamr@2
   478
                                 (const unsigned char*) __first2,
williamr@2
   479
                                 (const unsigned char*) __last2);
williamr@2
   480
}
williamr@2
   481
#endif /* CHAR_MAX == SCHAR_MAX */
williamr@2
   482
williamr@2
   483
template <class _InputIter1, class _InputIter2>
williamr@2
   484
int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   485
                                   _InputIter2 __first2, _InputIter2 __last2);
williamr@2
   486
williamr@2
   487
inline int
williamr@2
   488
__lexicographical_compare_3way(const unsigned char* __first1,
williamr@2
   489
                               const unsigned char* __last1,
williamr@2
   490
                               const unsigned char* __first2,
williamr@2
   491
                               const unsigned char* __last2)
williamr@2
   492
{
williamr@2
   493
  const ptrdiff_t __len1 = __last1 - __first1;
williamr@2
   494
  const ptrdiff_t __len2 = __last2 - __first2;
williamr@2
   495
  const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
williamr@2
   496
  return __result != 0 ? __result 
williamr@2
   497
                       : (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
williamr@2
   498
}
williamr@2
   499
williamr@2
   500
williamr@2
   501
# if !(CHAR_MAX == SCHAR_MAX)
williamr@2
   502
inline int 
williamr@2
   503
__lexicographical_compare_3way(const char* __first1, const char* __last1,
williamr@2
   504
                               const char* __first2, const char* __last2)
williamr@2
   505
{
williamr@2
   506
  return __lexicographical_compare_3way((const unsigned char*) __first1,
williamr@2
   507
                                        (const unsigned char*) __last1,
williamr@2
   508
                                        (const unsigned char*) __first2,
williamr@2
   509
                                        (const unsigned char*) __last2);
williamr@2
   510
}
williamr@2
   511
# endif
williamr@2
   512
williamr@2
   513
# ifndef _STLP_NO_EXTENSIONS
williamr@2
   514
williamr@2
   515
template <class _InputIter1, class _InputIter2>
williamr@2
   516
int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
williamr@2
   517
                                 _InputIter2 __first2, _InputIter2 __last2);
williamr@2
   518
williamr@2
   519
# endif /* EXTENSIONS */
williamr@2
   520
williamr@2
   521
// count
williamr@2
   522
template <class _InputIter, class _Tp>
williamr@2
   523
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
williamr@2
   524
count(_InputIter __first, _InputIter __last, const _Tp& __val) {
williamr@2
   525
  _STLP_DEBUG_CHECK(__check_range(__first, __last))
williamr@2
   526
  _STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
williamr@2
   527
  for ( ; __first != __last; ++__first)
williamr@2
   528
    if (*__first == __val)
williamr@2
   529
      ++__n;
williamr@2
   530
  return __n;
williamr@2
   531
}
williamr@2
   532
williamr@2
   533
// find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
williamr@2
   534
template <class _InputIter, class _Tp>
williamr@2
   535
_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
williamr@2
   536
template <class _InputIter, class _Predicate>
williamr@2
   537
_InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
williamr@2
   538
williamr@2
   539
// search.
williamr@2
   540
template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
williamr@2
   541
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
williamr@2
   542
                     _ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred  __predicate);
williamr@2
   543
williamr@2
   544
// find_first_of
williamr@2
   545
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
williamr@2
   546
_InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
williamr@2
   547
                           _ForwardIter __first2, _ForwardIter __last2,
williamr@2
   548
                           _BinaryPredicate __comp);
williamr@2
   549
williamr@2
   550
template <class _ForwardIter1, class _ForwardIter2, 
williamr@2
   551
          class _BinaryPredicate>
williamr@2
   552
_ForwardIter1 
williamr@2
   553
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1, 
williamr@2
   554
         _ForwardIter2 __first2, _ForwardIter2 __last2,
williamr@2
   555
         _BinaryPredicate __comp);
williamr@2
   556
williamr@2
   557
// replace
williamr@2
   558
template <class _ForwardIter, class _Tp>
williamr@2
   559
_STLP_INLINE_LOOP void 
williamr@2
   560
replace(_ForwardIter __first, _ForwardIter __last,
williamr@2
   561
        const _Tp& __old_value, const _Tp& __new_value) {
williamr@2
   562
  _STLP_DEBUG_CHECK(__check_range(__first, __last))
williamr@2
   563
  for ( ; __first != __last; ++__first)
williamr@2
   564
    if (*__first == __old_value)
williamr@2
   565
      *__first = __new_value;
williamr@2
   566
}
williamr@2
   567
williamr@2
   568
template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
williamr@2
   569
_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
williamr@2
   570
                              const _Tp& __val, _Compare __comp, _Distance*);
williamr@2
   571
williamr@2
   572
_STLP_END_NAMESPACE
williamr@2
   573
williamr@2
   574
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@2
   575
#  include <stl/_algobase.c>
williamr@2
   576
# endif
williamr@2
   577
williamr@2
   578
#endif /* _STLP_INTERNAL_ALGOBASE_H */
williamr@2
   579
williamr@2
   580
// Local Variables:
williamr@2
   581
// mode:C++
williamr@2
   582
// End:
williamr@2
   583