OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [bits/] [stl_algobase.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Core algorithmic facilities -*- C++ -*-
2
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4
// 2011, 2012 Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
/*
27
 *
28
 * Copyright (c) 1994
29
 * Hewlett-Packard Company
30
 *
31
 * Permission to use, copy, modify, distribute and sell this software
32
 * and its documentation for any purpose is hereby granted without fee,
33
 * provided that the above copyright notice appear in all copies and
34
 * that both that copyright notice and this permission notice appear
35
 * in supporting documentation.  Hewlett-Packard Company makes no
36
 * representations about the suitability of this software for any
37
 * purpose.  It is provided "as is" without express or implied warranty.
38
 *
39
 *
40
 * Copyright (c) 1996-1998
41
 * Silicon Graphics Computer Systems, Inc.
42
 *
43
 * Permission to use, copy, modify, distribute and sell this software
44
 * and its documentation for any purpose is hereby granted without fee,
45
 * provided that the above copyright notice appear in all copies and
46
 * that both that copyright notice and this permission notice appear
47
 * in supporting documentation.  Silicon Graphics makes no
48
 * representations about the suitability of this software for any
49
 * purpose.  It is provided "as is" without express or implied warranty.
50
 */
51
 
52
/** @file bits/stl_algobase.h
53
 *  This is an internal header file, included by other library headers.
54
 *  Do not attempt to use it directly. @headername{algorithm}
55
 */
56
 
57
#ifndef _STL_ALGOBASE_H
58
#define _STL_ALGOBASE_H 1
59
 
60
#include <bits/c++config.h>
61
#include <bits/functexcept.h>
62
#include <bits/cpp_type_traits.h>
63
#include <ext/type_traits.h>
64
#include <ext/numeric_traits.h>
65
#include <bits/stl_pair.h>
66
#include <bits/stl_iterator_base_types.h>
67
#include <bits/stl_iterator_base_funcs.h>
68
#include <bits/stl_iterator.h>
69
#include <bits/concept_check.h>
70
#include <debug/debug.h>
71
#include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
72
 
73
namespace std _GLIBCXX_VISIBILITY(default)
74
{
75
_GLIBCXX_BEGIN_NAMESPACE_VERSION
76
 
77
#if __cplusplus < 201103L
78
  // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
79
  // nutshell, we are partially implementing the resolution of DR 187,
80
  // when it's safe, i.e., the value_types are equal.
81
  template<bool _BoolType>
82
    struct __iter_swap
83
    {
84
      template<typename _ForwardIterator1, typename _ForwardIterator2>
85
        static void
86
        iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
87
        {
88
          typedef typename iterator_traits<_ForwardIterator1>::value_type
89
            _ValueType1;
90
          _ValueType1 __tmp = _GLIBCXX_MOVE(*__a);
91
          *__a = _GLIBCXX_MOVE(*__b);
92
          *__b = _GLIBCXX_MOVE(__tmp);
93
        }
94
    };
95
 
96
  template<>
97
    struct __iter_swap<true>
98
    {
99
      template<typename _ForwardIterator1, typename _ForwardIterator2>
100
        static void
101
        iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
102
        {
103
          swap(*__a, *__b);
104
        }
105
    };
106
#endif
107
 
108
  /**
109
   *  @brief Swaps the contents of two iterators.
110
   *  @ingroup mutating_algorithms
111
   *  @param  __a  An iterator.
112
   *  @param  __b  Another iterator.
113
   *  @return   Nothing.
114
   *
115
   *  This function swaps the values pointed to by two iterators, not the
116
   *  iterators themselves.
117
  */
118
  template<typename _ForwardIterator1, typename _ForwardIterator2>
119
    inline void
120
    iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
121
    {
122
      // concept requirements
123
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
124
                                  _ForwardIterator1>)
125
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
126
                                  _ForwardIterator2>)
127
 
128
#if __cplusplus < 201103L
129
      typedef typename iterator_traits<_ForwardIterator1>::value_type
130
        _ValueType1;
131
      typedef typename iterator_traits<_ForwardIterator2>::value_type
132
        _ValueType2;
133
 
134
      __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
135
                                  _ValueType2>)
136
      __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
137
                                  _ValueType1>)
138
 
139
      typedef typename iterator_traits<_ForwardIterator1>::reference
140
        _ReferenceType1;
141
      typedef typename iterator_traits<_ForwardIterator2>::reference
142
        _ReferenceType2;
143
      std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
144
        && __are_same<_ValueType1&, _ReferenceType1>::__value
145
        && __are_same<_ValueType2&, _ReferenceType2>::__value>::
146
        iter_swap(__a, __b);
147
#else
148
      swap(*__a, *__b);
149
#endif
150
    }
151
 
152
  /**
153
   *  @brief Swap the elements of two sequences.
154
   *  @ingroup mutating_algorithms
155
   *  @param  __first1  A forward iterator.
156
   *  @param  __last1   A forward iterator.
157
   *  @param  __first2  A forward iterator.
158
   *  @return   An iterator equal to @p first2+(last1-first1).
159
   *
160
   *  Swaps each element in the range @p [first1,last1) with the
161
   *  corresponding element in the range @p [first2,(last1-first1)).
162
   *  The ranges must not overlap.
163
  */
164
  template<typename _ForwardIterator1, typename _ForwardIterator2>
165
    _ForwardIterator2
166
    swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
167
                _ForwardIterator2 __first2)
168
    {
169
      // concept requirements
170
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
171
                                  _ForwardIterator1>)
172
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
173
                                  _ForwardIterator2>)
174
      __glibcxx_requires_valid_range(__first1, __last1);
175
 
176
      for (; __first1 != __last1; ++__first1, ++__first2)
177
        std::iter_swap(__first1, __first2);
178
      return __first2;
179
    }
180
 
181
  /**
182
   *  @brief This does what you think it does.
183
   *  @ingroup sorting_algorithms
184
   *  @param  __a  A thing of arbitrary type.
185
   *  @param  __b  Another thing of arbitrary type.
186
   *  @return   The lesser of the parameters.
187
   *
188
   *  This is the simple classic generic implementation.  It will work on
189
   *  temporary expressions, since they are only evaluated once, unlike a
190
   *  preprocessor macro.
191
  */
192
  template<typename _Tp>
193
    inline const _Tp&
194
    min(const _Tp& __a, const _Tp& __b)
195
    {
196
      // concept requirements
197
      __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
198
      //return __b < __a ? __b : __a;
199
      if (__b < __a)
200
        return __b;
201
      return __a;
202
    }
203
 
204
  /**
205
   *  @brief This does what you think it does.
206
   *  @ingroup sorting_algorithms
207
   *  @param  __a  A thing of arbitrary type.
208
   *  @param  __b  Another thing of arbitrary type.
209
   *  @return   The greater of the parameters.
210
   *
211
   *  This is the simple classic generic implementation.  It will work on
212
   *  temporary expressions, since they are only evaluated once, unlike a
213
   *  preprocessor macro.
214
  */
215
  template<typename _Tp>
216
    inline const _Tp&
217
    max(const _Tp& __a, const _Tp& __b)
218
    {
219
      // concept requirements
220
      __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
221
      //return  __a < __b ? __b : __a;
222
      if (__a < __b)
223
        return __b;
224
      return __a;
225
    }
226
 
227
  /**
228
   *  @brief This does what you think it does.
229
   *  @ingroup sorting_algorithms
230
   *  @param  __a  A thing of arbitrary type.
231
   *  @param  __b  Another thing of arbitrary type.
232
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
233
   *  @return   The lesser of the parameters.
234
   *
235
   *  This will work on temporary expressions, since they are only evaluated
236
   *  once, unlike a preprocessor macro.
237
  */
238
  template<typename _Tp, typename _Compare>
239
    inline const _Tp&
240
    min(const _Tp& __a, const _Tp& __b, _Compare __comp)
241
    {
242
      //return __comp(__b, __a) ? __b : __a;
243
      if (__comp(__b, __a))
244
        return __b;
245
      return __a;
246
    }
247
 
248
  /**
249
   *  @brief This does what you think it does.
250
   *  @ingroup sorting_algorithms
251
   *  @param  __a  A thing of arbitrary type.
252
   *  @param  __b  Another thing of arbitrary type.
253
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
254
   *  @return   The greater of the parameters.
255
   *
256
   *  This will work on temporary expressions, since they are only evaluated
257
   *  once, unlike a preprocessor macro.
258
  */
259
  template<typename _Tp, typename _Compare>
260
    inline const _Tp&
261
    max(const _Tp& __a, const _Tp& __b, _Compare __comp)
262
    {
263
      //return __comp(__a, __b) ? __b : __a;
264
      if (__comp(__a, __b))
265
        return __b;
266
      return __a;
267
    }
268
 
269
  // If _Iterator is a __normal_iterator return its base (a plain pointer,
270
  // normally) otherwise return it untouched.  See copy, fill, ... 
271
  template<typename _Iterator>
272
    struct _Niter_base
273
    : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value>
274
    { };
275
 
276
  template<typename _Iterator>
277
    inline typename _Niter_base<_Iterator>::iterator_type
278
    __niter_base(_Iterator __it)
279
    { return std::_Niter_base<_Iterator>::_S_base(__it); }
280
 
281
  // Likewise, for move_iterator.
282
  template<typename _Iterator>
283
    struct _Miter_base
284
    : _Iter_base<_Iterator, __is_move_iterator<_Iterator>::__value>
285
    { };
286
 
287
  template<typename _Iterator>
288
    inline typename _Miter_base<_Iterator>::iterator_type
289
    __miter_base(_Iterator __it)
290
    { return std::_Miter_base<_Iterator>::_S_base(__it); }
291
 
292
  // All of these auxiliary structs serve two purposes.  (1) Replace
293
  // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
294
  // because the input and output ranges are permitted to overlap.)
295
  // (2) If we're using random access iterators, then write the loop as
296
  // a for loop with an explicit count.
297
 
298
  template<bool, bool, typename>
299
    struct __copy_move
300
    {
301
      template<typename _II, typename _OI>
302
        static _OI
303
        __copy_m(_II __first, _II __last, _OI __result)
304
        {
305
          for (; __first != __last; ++__result, ++__first)
306
            *__result = *__first;
307
          return __result;
308
        }
309
    };
310
 
311
#if __cplusplus >= 201103L
312
  template<typename _Category>
313
    struct __copy_move<true, false, _Category>
314
    {
315
      template<typename _II, typename _OI>
316
        static _OI
317
        __copy_m(_II __first, _II __last, _OI __result)
318
        {
319
          for (; __first != __last; ++__result, ++__first)
320
            *__result = std::move(*__first);
321
          return __result;
322
        }
323
    };
324
#endif
325
 
326
  template<>
327
    struct __copy_move<false, false, random_access_iterator_tag>
328
    {
329
      template<typename _II, typename _OI>
330
        static _OI
331
        __copy_m(_II __first, _II __last, _OI __result)
332
        {
333
          typedef typename iterator_traits<_II>::difference_type _Distance;
334
          for(_Distance __n = __last - __first; __n > 0; --__n)
335
            {
336
              *__result = *__first;
337
              ++__first;
338
              ++__result;
339
            }
340
          return __result;
341
        }
342
    };
343
 
344
#if __cplusplus >= 201103L
345
  template<>
346
    struct __copy_move<true, false, random_access_iterator_tag>
347
    {
348
      template<typename _II, typename _OI>
349
        static _OI
350
        __copy_m(_II __first, _II __last, _OI __result)
351
        {
352
          typedef typename iterator_traits<_II>::difference_type _Distance;
353
          for(_Distance __n = __last - __first; __n > 0; --__n)
354
            {
355
              *__result = std::move(*__first);
356
              ++__first;
357
              ++__result;
358
            }
359
          return __result;
360
        }
361
    };
362
#endif
363
 
364
  template<bool _IsMove>
365
    struct __copy_move<_IsMove, true, random_access_iterator_tag>
366
    {
367
      template<typename _Tp>
368
        static _Tp*
369
        __copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
370
        {
371
          const ptrdiff_t _Num = __last - __first;
372
          if (_Num)
373
            __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
374
          return __result + _Num;
375
        }
376
    };
377
 
378
  template<bool _IsMove, typename _II, typename _OI>
379
    inline _OI
380
    __copy_move_a(_II __first, _II __last, _OI __result)
381
    {
382
      typedef typename iterator_traits<_II>::value_type _ValueTypeI;
383
      typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
384
      typedef typename iterator_traits<_II>::iterator_category _Category;
385
      const bool __simple = (__is_trivial(_ValueTypeI)
386
                             && __is_pointer<_II>::__value
387
                             && __is_pointer<_OI>::__value
388
                             && __are_same<_ValueTypeI, _ValueTypeO>::__value);
389
 
390
      return std::__copy_move<_IsMove, __simple,
391
                              _Category>::__copy_m(__first, __last, __result);
392
    }
393
 
394
  // Helpers for streambuf iterators (either istream or ostream).
395
  // NB: avoid including <iosfwd>, relatively large.
396
  template<typename _CharT>
397
    struct char_traits;
398
 
399
  template<typename _CharT, typename _Traits>
400
    class istreambuf_iterator;
401
 
402
  template<typename _CharT, typename _Traits>
403
    class ostreambuf_iterator;
404
 
405
  template<bool _IsMove, typename _CharT>
406
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
407
             ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
408
    __copy_move_a2(_CharT*, _CharT*,
409
                   ostreambuf_iterator<_CharT, char_traits<_CharT> >);
410
 
411
  template<bool _IsMove, typename _CharT>
412
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
413
             ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
414
    __copy_move_a2(const _CharT*, const _CharT*,
415
                   ostreambuf_iterator<_CharT, char_traits<_CharT> >);
416
 
417
  template<bool _IsMove, typename _CharT>
418
    typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
419
                                    _CharT*>::__type
420
    __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
421
                   istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
422
 
423
  template<bool _IsMove, typename _II, typename _OI>
424
    inline _OI
425
    __copy_move_a2(_II __first, _II __last, _OI __result)
426
    {
427
      return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
428
                                             std::__niter_base(__last),
429
                                             std::__niter_base(__result)));
430
    }
431
 
432
  /**
433
   *  @brief Copies the range [first,last) into result.
434
   *  @ingroup mutating_algorithms
435
   *  @param  __first  An input iterator.
436
   *  @param  __last   An input iterator.
437
   *  @param  __result An output iterator.
438
   *  @return   result + (first - last)
439
   *
440
   *  This inline function will boil down to a call to @c memmove whenever
441
   *  possible.  Failing that, if random access iterators are passed, then the
442
   *  loop count will be known (and therefore a candidate for compiler
443
   *  optimizations such as unrolling).  Result may not be contained within
444
   *  [first,last); the copy_backward function should be used instead.
445
   *
446
   *  Note that the end of the output range is permitted to be contained
447
   *  within [first,last).
448
  */
449
  template<typename _II, typename _OI>
450
    inline _OI
451
    copy(_II __first, _II __last, _OI __result)
452
    {
453
      // concept requirements
454
      __glibcxx_function_requires(_InputIteratorConcept<_II>)
455
      __glibcxx_function_requires(_OutputIteratorConcept<_OI,
456
            typename iterator_traits<_II>::value_type>)
457
      __glibcxx_requires_valid_range(__first, __last);
458
 
459
      return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
460
              (std::__miter_base(__first), std::__miter_base(__last),
461
               __result));
462
    }
463
 
464
#if __cplusplus >= 201103L
465
  /**
466
   *  @brief Moves the range [first,last) into result.
467
   *  @ingroup mutating_algorithms
468
   *  @param  __first  An input iterator.
469
   *  @param  __last   An input iterator.
470
   *  @param  __result An output iterator.
471
   *  @return   result + (first - last)
472
   *
473
   *  This inline function will boil down to a call to @c memmove whenever
474
   *  possible.  Failing that, if random access iterators are passed, then the
475
   *  loop count will be known (and therefore a candidate for compiler
476
   *  optimizations such as unrolling).  Result may not be contained within
477
   *  [first,last); the move_backward function should be used instead.
478
   *
479
   *  Note that the end of the output range is permitted to be contained
480
   *  within [first,last).
481
  */
482
  template<typename _II, typename _OI>
483
    inline _OI
484
    move(_II __first, _II __last, _OI __result)
485
    {
486
      // concept requirements
487
      __glibcxx_function_requires(_InputIteratorConcept<_II>)
488
      __glibcxx_function_requires(_OutputIteratorConcept<_OI,
489
            typename iterator_traits<_II>::value_type>)
490
      __glibcxx_requires_valid_range(__first, __last);
491
 
492
      return std::__copy_move_a2<true>(std::__miter_base(__first),
493
                                       std::__miter_base(__last), __result);
494
    }
495
 
496
#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
497
#else
498
#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
499
#endif
500
 
501
  template<bool, bool, typename>
502
    struct __copy_move_backward
503
    {
504
      template<typename _BI1, typename _BI2>
505
        static _BI2
506
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
507
        {
508
          while (__first != __last)
509
            *--__result = *--__last;
510
          return __result;
511
        }
512
    };
513
 
514
#if __cplusplus >= 201103L
515
  template<typename _Category>
516
    struct __copy_move_backward<true, false, _Category>
517
    {
518
      template<typename _BI1, typename _BI2>
519
        static _BI2
520
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
521
        {
522
          while (__first != __last)
523
            *--__result = std::move(*--__last);
524
          return __result;
525
        }
526
    };
527
#endif
528
 
529
  template<>
530
    struct __copy_move_backward<false, false, random_access_iterator_tag>
531
    {
532
      template<typename _BI1, typename _BI2>
533
        static _BI2
534
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
535
        {
536
          typename iterator_traits<_BI1>::difference_type __n;
537
          for (__n = __last - __first; __n > 0; --__n)
538
            *--__result = *--__last;
539
          return __result;
540
        }
541
    };
542
 
543
#if __cplusplus >= 201103L
544
  template<>
545
    struct __copy_move_backward<true, false, random_access_iterator_tag>
546
    {
547
      template<typename _BI1, typename _BI2>
548
        static _BI2
549
        __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
550
        {
551
          typename iterator_traits<_BI1>::difference_type __n;
552
          for (__n = __last - __first; __n > 0; --__n)
553
            *--__result = std::move(*--__last);
554
          return __result;
555
        }
556
    };
557
#endif
558
 
559
  template<bool _IsMove>
560
    struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
561
    {
562
      template<typename _Tp>
563
        static _Tp*
564
        __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result)
565
        {
566
          const ptrdiff_t _Num = __last - __first;
567
          if (_Num)
568
            __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
569
          return __result - _Num;
570
        }
571
    };
572
 
573
  template<bool _IsMove, typename _BI1, typename _BI2>
574
    inline _BI2
575
    __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
576
    {
577
      typedef typename iterator_traits<_BI1>::value_type _ValueType1;
578
      typedef typename iterator_traits<_BI2>::value_type _ValueType2;
579
      typedef typename iterator_traits<_BI1>::iterator_category _Category;
580
      const bool __simple = (__is_trivial(_ValueType1)
581
                             && __is_pointer<_BI1>::__value
582
                             && __is_pointer<_BI2>::__value
583
                             && __are_same<_ValueType1, _ValueType2>::__value);
584
 
585
      return std::__copy_move_backward<_IsMove, __simple,
586
                                       _Category>::__copy_move_b(__first,
587
                                                                 __last,
588
                                                                 __result);
589
    }
590
 
591
  template<bool _IsMove, typename _BI1, typename _BI2>
592
    inline _BI2
593
    __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
594
    {
595
      return _BI2(std::__copy_move_backward_a<_IsMove>
596
                  (std::__niter_base(__first), std::__niter_base(__last),
597
                   std::__niter_base(__result)));
598
    }
599
 
600
  /**
601
   *  @brief Copies the range [first,last) into result.
602
   *  @ingroup mutating_algorithms
603
   *  @param  __first  A bidirectional iterator.
604
   *  @param  __last   A bidirectional iterator.
605
   *  @param  __result A bidirectional iterator.
606
   *  @return   result - (first - last)
607
   *
608
   *  The function has the same effect as copy, but starts at the end of the
609
   *  range and works its way to the start, returning the start of the result.
610
   *  This inline function will boil down to a call to @c memmove whenever
611
   *  possible.  Failing that, if random access iterators are passed, then the
612
   *  loop count will be known (and therefore a candidate for compiler
613
   *  optimizations such as unrolling).
614
   *
615
   *  Result may not be in the range [first,last).  Use copy instead.  Note
616
   *  that the start of the output range may overlap [first,last).
617
  */
618
  template<typename _BI1, typename _BI2>
619
    inline _BI2
620
    copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
621
    {
622
      // concept requirements
623
      __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
624
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
625
      __glibcxx_function_requires(_ConvertibleConcept<
626
            typename iterator_traits<_BI1>::value_type,
627
            typename iterator_traits<_BI2>::value_type>)
628
      __glibcxx_requires_valid_range(__first, __last);
629
 
630
      return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
631
              (std::__miter_base(__first), std::__miter_base(__last),
632
               __result));
633
    }
634
 
635
#if __cplusplus >= 201103L
636
  /**
637
   *  @brief Moves the range [first,last) into result.
638
   *  @ingroup mutating_algorithms
639
   *  @param  __first  A bidirectional iterator.
640
   *  @param  __last   A bidirectional iterator.
641
   *  @param  __result A bidirectional iterator.
642
   *  @return   result - (first - last)
643
   *
644
   *  The function has the same effect as move, but starts at the end of the
645
   *  range and works its way to the start, returning the start of the result.
646
   *  This inline function will boil down to a call to @c memmove whenever
647
   *  possible.  Failing that, if random access iterators are passed, then the
648
   *  loop count will be known (and therefore a candidate for compiler
649
   *  optimizations such as unrolling).
650
   *
651
   *  Result may not be in the range (first,last].  Use move instead.  Note
652
   *  that the start of the output range may overlap [first,last).
653
  */
654
  template<typename _BI1, typename _BI2>
655
    inline _BI2
656
    move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
657
    {
658
      // concept requirements
659
      __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
660
      __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
661
      __glibcxx_function_requires(_ConvertibleConcept<
662
            typename iterator_traits<_BI1>::value_type,
663
            typename iterator_traits<_BI2>::value_type>)
664
      __glibcxx_requires_valid_range(__first, __last);
665
 
666
      return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
667
                                                std::__miter_base(__last),
668
                                                __result);
669
    }
670
 
671
#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
672
#else
673
#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
674
#endif
675
 
676
  template<typename _ForwardIterator, typename _Tp>
677
    inline typename
678
    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
679
    __fill_a(_ForwardIterator __first, _ForwardIterator __last,
680
             const _Tp& __value)
681
    {
682
      for (; __first != __last; ++__first)
683
        *__first = __value;
684
    }
685
 
686
  template<typename _ForwardIterator, typename _Tp>
687
    inline typename
688
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
689
    __fill_a(_ForwardIterator __first, _ForwardIterator __last,
690
             const _Tp& __value)
691
    {
692
      const _Tp __tmp = __value;
693
      for (; __first != __last; ++__first)
694
        *__first = __tmp;
695
    }
696
 
697
  // Specialization: for char types we can use memset.
698
  template<typename _Tp>
699
    inline typename
700
    __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
701
    __fill_a(_Tp* __first, _Tp* __last, const _Tp& __c)
702
    {
703
      const _Tp __tmp = __c;
704
      __builtin_memset(__first, static_cast<unsigned char>(__tmp),
705
                       __last - __first);
706
    }
707
 
708
  /**
709
   *  @brief Fills the range [first,last) with copies of value.
710
   *  @ingroup mutating_algorithms
711
   *  @param  __first  A forward iterator.
712
   *  @param  __last   A forward iterator.
713
   *  @param  __value  A reference-to-const of arbitrary type.
714
   *  @return   Nothing.
715
   *
716
   *  This function fills a range with copies of the same value.  For char
717
   *  types filling contiguous areas of memory, this becomes an inline call
718
   *  to @c memset or @c wmemset.
719
  */
720
  template<typename _ForwardIterator, typename _Tp>
721
    inline void
722
    fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
723
    {
724
      // concept requirements
725
      __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
726
                                  _ForwardIterator>)
727
      __glibcxx_requires_valid_range(__first, __last);
728
 
729
      std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
730
                    __value);
731
    }
732
 
733
  template<typename _OutputIterator, typename _Size, typename _Tp>
734
    inline typename
735
    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
736
    __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
737
    {
738
      for (__decltype(__n + 0) __niter = __n;
739
           __niter > 0; --__niter, ++__first)
740
        *__first = __value;
741
      return __first;
742
    }
743
 
744
  template<typename _OutputIterator, typename _Size, typename _Tp>
745
    inline typename
746
    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
747
    __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
748
    {
749
      const _Tp __tmp = __value;
750
      for (__decltype(__n + 0) __niter = __n;
751
           __niter > 0; --__niter, ++__first)
752
        *__first = __tmp;
753
      return __first;
754
    }
755
 
756
  template<typename _Size, typename _Tp>
757
    inline typename
758
    __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
759
    __fill_n_a(_Tp* __first, _Size __n, const _Tp& __c)
760
    {
761
      std::__fill_a(__first, __first + __n, __c);
762
      return __first + __n;
763
    }
764
 
765
  /**
766
   *  @brief Fills the range [first,first+n) with copies of value.
767
   *  @ingroup mutating_algorithms
768
   *  @param  __first  An output iterator.
769
   *  @param  __n      The count of copies to perform.
770
   *  @param  __value  A reference-to-const of arbitrary type.
771
   *  @return   The iterator at first+n.
772
   *
773
   *  This function fills a range with copies of the same value.  For char
774
   *  types filling contiguous areas of memory, this becomes an inline call
775
   *  to @c memset or @ wmemset.
776
   *
777
   *  _GLIBCXX_RESOLVE_LIB_DEFECTS
778
   *  DR 865. More algorithms that throw away information
779
  */
780
  template<typename _OI, typename _Size, typename _Tp>
781
    inline _OI
782
    fill_n(_OI __first, _Size __n, const _Tp& __value)
783
    {
784
      // concept requirements
785
      __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
786
 
787
      return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
788
    }
789
 
790
  template<bool _BoolType>
791
    struct __equal
792
    {
793
      template<typename _II1, typename _II2>
794
        static bool
795
        equal(_II1 __first1, _II1 __last1, _II2 __first2)
796
        {
797
          for (; __first1 != __last1; ++__first1, ++__first2)
798
            if (!(*__first1 == *__first2))
799
              return false;
800
          return true;
801
        }
802
    };
803
 
804
  template<>
805
    struct __equal<true>
806
    {
807
      template<typename _Tp>
808
        static bool
809
        equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2)
810
        {
811
          return !__builtin_memcmp(__first1, __first2, sizeof(_Tp)
812
                                   * (__last1 - __first1));
813
        }
814
    };
815
 
816
  template<typename _II1, typename _II2>
817
    inline bool
818
    __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
819
    {
820
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
821
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
822
      const bool __simple = ((__is_integer<_ValueType1>::__value
823
                              || __is_pointer<_ValueType1>::__value)
824
                             && __is_pointer<_II1>::__value
825
                             && __is_pointer<_II2>::__value
826
                             && __are_same<_ValueType1, _ValueType2>::__value);
827
 
828
      return std::__equal<__simple>::equal(__first1, __last1, __first2);
829
    }
830
 
831
 
832
  template<typename, typename>
833
    struct __lc_rai
834
    {
835
      template<typename _II1, typename _II2>
836
        static _II1
837
        __newlast1(_II1, _II1 __last1, _II2, _II2)
838
        { return __last1; }
839
 
840
      template<typename _II>
841
        static bool
842
        __cnd2(_II __first, _II __last)
843
        { return __first != __last; }
844
    };
845
 
846
  template<>
847
    struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
848
    {
849
      template<typename _RAI1, typename _RAI2>
850
        static _RAI1
851
        __newlast1(_RAI1 __first1, _RAI1 __last1,
852
                   _RAI2 __first2, _RAI2 __last2)
853
        {
854
          const typename iterator_traits<_RAI1>::difference_type
855
            __diff1 = __last1 - __first1;
856
          const typename iterator_traits<_RAI2>::difference_type
857
            __diff2 = __last2 - __first2;
858
          return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
859
        }
860
 
861
      template<typename _RAI>
862
        static bool
863
        __cnd2(_RAI, _RAI)
864
        { return true; }
865
    };
866
 
867
  template<bool _BoolType>
868
    struct __lexicographical_compare
869
    {
870
      template<typename _II1, typename _II2>
871
        static bool __lc(_II1, _II1, _II2, _II2);
872
    };
873
 
874
  template<bool _BoolType>
875
    template<typename _II1, typename _II2>
876
      bool
877
      __lexicographical_compare<_BoolType>::
878
      __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
879
      {
880
        typedef typename iterator_traits<_II1>::iterator_category _Category1;
881
        typedef typename iterator_traits<_II2>::iterator_category _Category2;
882
        typedef std::__lc_rai<_Category1, _Category2>   __rai_type;
883
 
884
        __last1 = __rai_type::__newlast1(__first1, __last1,
885
                                         __first2, __last2);
886
        for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
887
             ++__first1, ++__first2)
888
          {
889
            if (*__first1 < *__first2)
890
              return true;
891
            if (*__first2 < *__first1)
892
              return false;
893
          }
894
        return __first1 == __last1 && __first2 != __last2;
895
      }
896
 
897
  template<>
898
    struct __lexicographical_compare<true>
899
    {
900
      template<typename _Tp, typename _Up>
901
        static bool
902
        __lc(const _Tp* __first1, const _Tp* __last1,
903
             const _Up* __first2, const _Up* __last2)
904
        {
905
          const size_t __len1 = __last1 - __first1;
906
          const size_t __len2 = __last2 - __first2;
907
          const int __result = __builtin_memcmp(__first1, __first2,
908
                                                std::min(__len1, __len2));
909
          return __result != 0 ? __result < 0 : __len1 < __len2;
910
        }
911
    };
912
 
913
  template<typename _II1, typename _II2>
914
    inline bool
915
    __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
916
                                  _II2 __first2, _II2 __last2)
917
    {
918
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
919
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
920
      const bool __simple =
921
        (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
922
         && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
923
         && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
924
         && __is_pointer<_II1>::__value
925
         && __is_pointer<_II2>::__value);
926
 
927
      return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
928
                                                            __first2, __last2);
929
    }
930
 
931
  /**
932
   *  @brief Finds the first position in which @a val could be inserted
933
   *         without changing the ordering.
934
   *  @param  __first   An iterator.
935
   *  @param  __last    Another iterator.
936
   *  @param  __val     The search term.
937
   *  @return         An iterator pointing to the first element <em>not less
938
   *                  than</em> @a val, or end() if every element is less than
939
   *                  @a val.
940
   *  @ingroup binary_search_algorithms
941
  */
942
  template<typename _ForwardIterator, typename _Tp>
943
    _ForwardIterator
944
    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
945
                const _Tp& __val)
946
    {
947
#ifdef _GLIBCXX_CONCEPT_CHECKS
948
      typedef typename iterator_traits<_ForwardIterator>::value_type
949
        _ValueType;
950
#endif
951
      typedef typename iterator_traits<_ForwardIterator>::difference_type
952
        _DistanceType;
953
 
954
      // concept requirements
955
      __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
956
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
957
      __glibcxx_requires_partitioned_lower(__first, __last, __val);
958
 
959
      _DistanceType __len = std::distance(__first, __last);
960
 
961
      while (__len > 0)
962
        {
963
          _DistanceType __half = __len >> 1;
964
          _ForwardIterator __middle = __first;
965
          std::advance(__middle, __half);
966
          if (*__middle < __val)
967
            {
968
              __first = __middle;
969
              ++__first;
970
              __len = __len - __half - 1;
971
            }
972
          else
973
            __len = __half;
974
        }
975
      return __first;
976
    }
977
 
978
  /// This is a helper function for the sort routines and for random.tcc.
979
  //  Precondition: __n > 0.
980
  inline _GLIBCXX_CONSTEXPR int
981
  __lg(int __n)
982
  { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
983
 
984
  inline _GLIBCXX_CONSTEXPR unsigned
985
  __lg(unsigned __n)
986
  { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
987
 
988
  inline _GLIBCXX_CONSTEXPR long
989
  __lg(long __n)
990
  { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
991
 
992
  inline _GLIBCXX_CONSTEXPR unsigned long
993
  __lg(unsigned long __n)
994
  { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
995
 
996
  inline _GLIBCXX_CONSTEXPR long long
997
  __lg(long long __n)
998
  { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
999
 
1000
  inline _GLIBCXX_CONSTEXPR unsigned long long
1001
  __lg(unsigned long long __n)
1002
  { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
1003
 
1004
_GLIBCXX_END_NAMESPACE_VERSION
1005
 
1006
_GLIBCXX_BEGIN_NAMESPACE_ALGO
1007
 
1008
  /**
1009
   *  @brief Tests a range for element-wise equality.
1010
   *  @ingroup non_mutating_algorithms
1011
   *  @param  __first1  An input iterator.
1012
   *  @param  __last1   An input iterator.
1013
   *  @param  __first2  An input iterator.
1014
   *  @return   A boolean true or false.
1015
   *
1016
   *  This compares the elements of two ranges using @c == and returns true or
1017
   *  false depending on whether all of the corresponding elements of the
1018
   *  ranges are equal.
1019
  */
1020
  template<typename _II1, typename _II2>
1021
    inline bool
1022
    equal(_II1 __first1, _II1 __last1, _II2 __first2)
1023
    {
1024
      // concept requirements
1025
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1026
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1027
      __glibcxx_function_requires(_EqualOpConcept<
1028
            typename iterator_traits<_II1>::value_type,
1029
            typename iterator_traits<_II2>::value_type>)
1030
      __glibcxx_requires_valid_range(__first1, __last1);
1031
 
1032
      return std::__equal_aux(std::__niter_base(__first1),
1033
                              std::__niter_base(__last1),
1034
                              std::__niter_base(__first2));
1035
    }
1036
 
1037
  /**
1038
   *  @brief Tests a range for element-wise equality.
1039
   *  @ingroup non_mutating_algorithms
1040
   *  @param  __first1  An input iterator.
1041
   *  @param  __last1   An input iterator.
1042
   *  @param  __first2  An input iterator.
1043
   *  @param __binary_pred A binary predicate @link functors
1044
   *                  functor@endlink.
1045
   *  @return         A boolean true or false.
1046
   *
1047
   *  This compares the elements of two ranges using the binary_pred
1048
   *  parameter, and returns true or
1049
   *  false depending on whether all of the corresponding elements of the
1050
   *  ranges are equal.
1051
  */
1052
  template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
1053
    inline bool
1054
    equal(_IIter1 __first1, _IIter1 __last1,
1055
          _IIter2 __first2, _BinaryPredicate __binary_pred)
1056
    {
1057
      // concept requirements
1058
      __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1059
      __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1060
      __glibcxx_requires_valid_range(__first1, __last1);
1061
 
1062
      for (; __first1 != __last1; ++__first1, ++__first2)
1063
        if (!bool(__binary_pred(*__first1, *__first2)))
1064
          return false;
1065
      return true;
1066
    }
1067
 
1068
  /**
1069
   *  @brief Performs @b dictionary comparison on ranges.
1070
   *  @ingroup sorting_algorithms
1071
   *  @param  __first1  An input iterator.
1072
   *  @param  __last1   An input iterator.
1073
   *  @param  __first2  An input iterator.
1074
   *  @param  __last2   An input iterator.
1075
   *  @return   A boolean true or false.
1076
   *
1077
   *  <em>Returns true if the sequence of elements defined by the range
1078
   *  [first1,last1) is lexicographically less than the sequence of elements
1079
   *  defined by the range [first2,last2).  Returns false otherwise.</em>
1080
   *  (Quoted from [25.3.8]/1.)  If the iterators are all character pointers,
1081
   *  then this is an inline call to @c memcmp.
1082
  */
1083
  template<typename _II1, typename _II2>
1084
    inline bool
1085
    lexicographical_compare(_II1 __first1, _II1 __last1,
1086
                            _II2 __first2, _II2 __last2)
1087
    {
1088
#ifdef _GLIBCXX_CONCEPT_CHECKS
1089
      // concept requirements
1090
      typedef typename iterator_traits<_II1>::value_type _ValueType1;
1091
      typedef typename iterator_traits<_II2>::value_type _ValueType2;
1092
#endif
1093
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1094
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1095
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1096
      __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1097
      __glibcxx_requires_valid_range(__first1, __last1);
1098
      __glibcxx_requires_valid_range(__first2, __last2);
1099
 
1100
      return std::__lexicographical_compare_aux(std::__niter_base(__first1),
1101
                                                std::__niter_base(__last1),
1102
                                                std::__niter_base(__first2),
1103
                                                std::__niter_base(__last2));
1104
    }
1105
 
1106
  /**
1107
   *  @brief Performs @b dictionary comparison on ranges.
1108
   *  @ingroup sorting_algorithms
1109
   *  @param  __first1  An input iterator.
1110
   *  @param  __last1   An input iterator.
1111
   *  @param  __first2  An input iterator.
1112
   *  @param  __last2   An input iterator.
1113
   *  @param  __comp  A @link comparison_functors comparison functor@endlink.
1114
   *  @return   A boolean true or false.
1115
   *
1116
   *  The same as the four-parameter @c lexicographical_compare, but uses the
1117
   *  comp parameter instead of @c <.
1118
  */
1119
  template<typename _II1, typename _II2, typename _Compare>
1120
    bool
1121
    lexicographical_compare(_II1 __first1, _II1 __last1,
1122
                            _II2 __first2, _II2 __last2, _Compare __comp)
1123
    {
1124
      typedef typename iterator_traits<_II1>::iterator_category _Category1;
1125
      typedef typename iterator_traits<_II2>::iterator_category _Category2;
1126
      typedef std::__lc_rai<_Category1, _Category2>     __rai_type;
1127
 
1128
      // concept requirements
1129
      __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1130
      __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1131
      __glibcxx_requires_valid_range(__first1, __last1);
1132
      __glibcxx_requires_valid_range(__first2, __last2);
1133
 
1134
      __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1135
      for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1136
           ++__first1, ++__first2)
1137
        {
1138
          if (__comp(*__first1, *__first2))
1139
            return true;
1140
          if (__comp(*__first2, *__first1))
1141
            return false;
1142
        }
1143
      return __first1 == __last1 && __first2 != __last2;
1144
    }
1145
 
1146
  /**
1147
   *  @brief Finds the places in ranges which don't match.
1148
   *  @ingroup non_mutating_algorithms
1149
   *  @param  __first1  An input iterator.
1150
   *  @param  __last1   An input iterator.
1151
   *  @param  __first2  An input iterator.
1152
   *  @return   A pair of iterators pointing to the first mismatch.
1153
   *
1154
   *  This compares the elements of two ranges using @c == and returns a pair
1155
   *  of iterators.  The first iterator points into the first range, the
1156
   *  second iterator points into the second range, and the elements pointed
1157
   *  to by the iterators are not equal.
1158
  */
1159
  template<typename _InputIterator1, typename _InputIterator2>
1160
    pair<_InputIterator1, _InputIterator2>
1161
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1162
             _InputIterator2 __first2)
1163
    {
1164
      // concept requirements
1165
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1166
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1167
      __glibcxx_function_requires(_EqualOpConcept<
1168
            typename iterator_traits<_InputIterator1>::value_type,
1169
            typename iterator_traits<_InputIterator2>::value_type>)
1170
      __glibcxx_requires_valid_range(__first1, __last1);
1171
 
1172
      while (__first1 != __last1 && *__first1 == *__first2)
1173
        {
1174
          ++__first1;
1175
          ++__first2;
1176
        }
1177
      return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1178
    }
1179
 
1180
  /**
1181
   *  @brief Finds the places in ranges which don't match.
1182
   *  @ingroup non_mutating_algorithms
1183
   *  @param  __first1  An input iterator.
1184
   *  @param  __last1   An input iterator.
1185
   *  @param  __first2  An input iterator.
1186
   *  @param __binary_pred A binary predicate @link functors
1187
   *         functor@endlink.
1188
   *  @return   A pair of iterators pointing to the first mismatch.
1189
   *
1190
   *  This compares the elements of two ranges using the binary_pred
1191
   *  parameter, and returns a pair
1192
   *  of iterators.  The first iterator points into the first range, the
1193
   *  second iterator points into the second range, and the elements pointed
1194
   *  to by the iterators are not equal.
1195
  */
1196
  template<typename _InputIterator1, typename _InputIterator2,
1197
           typename _BinaryPredicate>
1198
    pair<_InputIterator1, _InputIterator2>
1199
    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1200
             _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1201
    {
1202
      // concept requirements
1203
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1204
      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1205
      __glibcxx_requires_valid_range(__first1, __last1);
1206
 
1207
      while (__first1 != __last1 && bool(__binary_pred(*__first1, *__first2)))
1208
        {
1209
          ++__first1;
1210
          ++__first2;
1211
        }
1212
      return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1213
    }
1214
 
1215
_GLIBCXX_END_NAMESPACE_ALGO
1216
} // namespace std
1217
 
1218
// NB: This file is included within many other C++ includes, as a way
1219
// of getting the base algorithms. So, make sure that parallel bits
1220
// come in too if requested. 
1221
#ifdef _GLIBCXX_PARALLEL
1222
# include <parallel/algobase.h>
1223
#endif
1224
 
1225
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.