1 // Core algorithmic facilities -*- C++ -*-
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 * Copyright (c) 1996-1998
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/stl_algobase.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{algorithm}
56 #ifndef _STL_ALGOBASE_H
57 #define _STL_ALGOBASE_H 1
59 #include <bits/c++config.h>
60 #include <bits/functexcept.h>
61 #include <bits/cpp_type_traits.h>
62 #include <ext/type_traits.h>
63 #include <ext/numeric_traits.h>
64 #include <bits/stl_pair.h>
65 #include <bits/stl_iterator_base_types.h>
66 #include <bits/stl_iterator_base_funcs.h>
67 #include <bits/stl_iterator.h>
68 #include <bits/concept_check.h>
69 #include <debug/debug.h>
70 #include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
71 #include <bits/predefined_ops.h>
73 namespace std
_GLIBCXX_VISIBILITY(default)
75 _GLIBCXX_BEGIN_NAMESPACE_VERSION
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
>
84 template<typename _ForwardIterator1
, typename _ForwardIterator2
>
86 iter_swap(_ForwardIterator1 __a
, _ForwardIterator2 __b
)
88 typedef typename iterator_traits
<_ForwardIterator1
>::value_type
90 _ValueType1 __tmp
= _GLIBCXX_MOVE(*__a
);
91 *__a
= _GLIBCXX_MOVE(*__b
);
92 *__b
= _GLIBCXX_MOVE(__tmp
);
97 struct __iter_swap
<true>
99 template<typename _ForwardIterator1
, typename _ForwardIterator2
>
101 iter_swap(_ForwardIterator1 __a
, _ForwardIterator2 __b
)
109 * @brief Swaps the contents of two iterators.
110 * @ingroup mutating_algorithms
111 * @param __a An iterator.
112 * @param __b Another iterator.
115 * This function swaps the values pointed to by two iterators, not the
116 * iterators themselves.
118 template<typename _ForwardIterator1
, typename _ForwardIterator2
>
120 iter_swap(_ForwardIterator1 __a
, _ForwardIterator2 __b
)
122 // concept requirements
123 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
125 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
128 #if __cplusplus < 201103L
129 typedef typename iterator_traits
<_ForwardIterator1
>::value_type
131 typedef typename iterator_traits
<_ForwardIterator2
>::value_type
134 __glibcxx_function_requires(_ConvertibleConcept
<_ValueType1
,
136 __glibcxx_function_requires(_ConvertibleConcept
<_ValueType2
,
139 typedef typename iterator_traits
<_ForwardIterator1
>::reference
141 typedef typename iterator_traits
<_ForwardIterator2
>::reference
143 std::__iter_swap
<__are_same
<_ValueType1
, _ValueType2
>::__value
144 && __are_same
<_ValueType1
&, _ReferenceType1
>::__value
145 && __are_same
<_ValueType2
&, _ReferenceType2
>::__value
>::
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).
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.
164 template<typename _ForwardIterator1
, typename _ForwardIterator2
>
166 swap_ranges(_ForwardIterator1 __first1
, _ForwardIterator1 __last1
,
167 _ForwardIterator2 __first2
)
169 // concept requirements
170 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
172 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
174 __glibcxx_requires_valid_range(__first1
, __last1
);
176 for (; __first1
!= __last1
; ++__first1
, ++__first2
)
177 std::iter_swap(__first1
, __first2
);
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.
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.
192 template<typename _Tp
>
194 min(const _Tp
& __a
, const _Tp
& __b
)
196 // concept requirements
197 __glibcxx_function_requires(_LessThanComparableConcept
<_Tp
>)
198 //return __b < __a ? __b : __a;
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.
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.
215 template<typename _Tp
>
217 max(const _Tp
& __a
, const _Tp
& __b
)
219 // concept requirements
220 __glibcxx_function_requires(_LessThanComparableConcept
<_Tp
>)
221 //return __a < __b ? __b : __a;
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.
235 * This will work on temporary expressions, since they are only evaluated
236 * once, unlike a preprocessor macro.
238 template<typename _Tp
, typename _Compare
>
240 min(const _Tp
& __a
, const _Tp
& __b
, _Compare __comp
)
242 //return __comp(__b, __a) ? __b : __a;
243 if (__comp(__b
, __a
))
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.
256 * This will work on temporary expressions, since they are only evaluated
257 * once, unlike a preprocessor macro.
259 template<typename _Tp
, typename _Compare
>
261 max(const _Tp
& __a
, const _Tp
& __b
, _Compare __comp
)
263 //return __comp(__a, __b) ? __b : __a;
264 if (__comp(__a
, __b
))
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
>
273 : _Iter_base
<_Iterator
, __is_normal_iterator
<_Iterator
>::__value
>
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
); }
281 // Likewise, for move_iterator.
282 template<typename _Iterator
>
284 : _Iter_base
<_Iterator
, __is_move_iterator
<_Iterator
>::__value
>
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
); }
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.
298 template<bool, bool, typename
>
301 template<typename _II
, typename _OI
>
303 __copy_m(_II __first
, _II __last
, _OI __result
)
305 for (; __first
!= __last
; ++__result
, ++__first
)
306 *__result
= *__first
;
311 #if __cplusplus >= 201103L
312 template<typename _Category
>
313 struct __copy_move
<true, false, _Category
>
315 template<typename _II
, typename _OI
>
317 __copy_m(_II __first
, _II __last
, _OI __result
)
319 for (; __first
!= __last
; ++__result
, ++__first
)
320 *__result
= std::move(*__first
);
327 struct __copy_move
<false, false, random_access_iterator_tag
>
329 template<typename _II
, typename _OI
>
331 __copy_m(_II __first
, _II __last
, _OI __result
)
333 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
334 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
336 *__result
= *__first
;
344 #if __cplusplus >= 201103L
346 struct __copy_move
<true, false, random_access_iterator_tag
>
348 template<typename _II
, typename _OI
>
350 __copy_m(_II __first
, _II __last
, _OI __result
)
352 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
353 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
355 *__result
= std::move(*__first
);
364 template<bool _IsMove
>
365 struct __copy_move
<_IsMove
, true, random_access_iterator_tag
>
367 template<typename _Tp
>
369 __copy_m(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
371 #if __cplusplus >= 201103L
372 // trivial types can have deleted assignment
373 static_assert( is_copy_assignable
<_Tp
>::value
,
374 "type is not assignable" );
376 const ptrdiff_t _Num
= __last
- __first
;
378 __builtin_memmove(__result
, __first
, sizeof(_Tp
) * _Num
);
379 return __result
+ _Num
;
383 template<bool _IsMove
, typename _II
, typename _OI
>
385 __copy_move_a(_II __first
, _II __last
, _OI __result
)
387 typedef typename iterator_traits
<_II
>::value_type _ValueTypeI
;
388 typedef typename iterator_traits
<_OI
>::value_type _ValueTypeO
;
389 typedef typename iterator_traits
<_II
>::iterator_category _Category
;
390 const bool __simple
= (__is_trivial(_ValueTypeI
)
391 && __is_pointer
<_II
>::__value
392 && __is_pointer
<_OI
>::__value
393 && __are_same
<_ValueTypeI
, _ValueTypeO
>::__value
);
395 return std::__copy_move
<_IsMove
, __simple
,
396 _Category
>::__copy_m(__first
, __last
, __result
);
399 // Helpers for streambuf iterators (either istream or ostream).
400 // NB: avoid including <iosfwd>, relatively large.
401 template<typename _CharT
>
404 template<typename _CharT
, typename _Traits
>
405 class istreambuf_iterator
;
407 template<typename _CharT
, typename _Traits
>
408 class ostreambuf_iterator
;
410 template<bool _IsMove
, typename _CharT
>
411 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
412 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> > >::__type
413 __copy_move_a2(_CharT
*, _CharT
*,
414 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
416 template<bool _IsMove
, typename _CharT
>
417 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
418 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> > >::__type
419 __copy_move_a2(const _CharT
*, const _CharT
*,
420 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
422 template<bool _IsMove
, typename _CharT
>
423 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
425 __copy_move_a2(istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >,
426 istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >, _CharT
*);
428 template<bool _IsMove
, typename _II
, typename _OI
>
430 __copy_move_a2(_II __first
, _II __last
, _OI __result
)
432 return _OI(std::__copy_move_a
<_IsMove
>(std::__niter_base(__first
),
433 std::__niter_base(__last
),
434 std::__niter_base(__result
)));
438 * @brief Copies the range [first,last) into result.
439 * @ingroup mutating_algorithms
440 * @param __first An input iterator.
441 * @param __last An input iterator.
442 * @param __result An output iterator.
443 * @return result + (first - last)
445 * This inline function will boil down to a call to @c memmove whenever
446 * possible. Failing that, if random access iterators are passed, then the
447 * loop count will be known (and therefore a candidate for compiler
448 * optimizations such as unrolling). Result may not be contained within
449 * [first,last); the copy_backward function should be used instead.
451 * Note that the end of the output range is permitted to be contained
452 * within [first,last).
454 template<typename _II
, typename _OI
>
456 copy(_II __first
, _II __last
, _OI __result
)
458 // concept requirements
459 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
460 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
461 typename iterator_traits
<_II
>::value_type
>)
462 __glibcxx_requires_valid_range(__first
, __last
);
464 return (std::__copy_move_a2
<__is_move_iterator
<_II
>::__value
>
465 (std::__miter_base(__first
), std::__miter_base(__last
),
469 #if __cplusplus >= 201103L
471 * @brief Moves the range [first,last) into result.
472 * @ingroup mutating_algorithms
473 * @param __first An input iterator.
474 * @param __last An input iterator.
475 * @param __result An output iterator.
476 * @return result + (first - last)
478 * This inline function will boil down to a call to @c memmove whenever
479 * possible. Failing that, if random access iterators are passed, then the
480 * loop count will be known (and therefore a candidate for compiler
481 * optimizations such as unrolling). Result may not be contained within
482 * [first,last); the move_backward function should be used instead.
484 * Note that the end of the output range is permitted to be contained
485 * within [first,last).
487 template<typename _II
, typename _OI
>
489 move(_II __first
, _II __last
, _OI __result
)
491 // concept requirements
492 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
493 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
494 typename iterator_traits
<_II
>::value_type
>)
495 __glibcxx_requires_valid_range(__first
, __last
);
497 return std::__copy_move_a2
<true>(std::__miter_base(__first
),
498 std::__miter_base(__last
), __result
);
501 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
503 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
506 template<bool, bool, typename
>
507 struct __copy_move_backward
509 template<typename _BI1
, typename _BI2
>
511 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
513 while (__first
!= __last
)
514 *--__result
= *--__last
;
519 #if __cplusplus >= 201103L
520 template<typename _Category
>
521 struct __copy_move_backward
<true, false, _Category
>
523 template<typename _BI1
, typename _BI2
>
525 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
527 while (__first
!= __last
)
528 *--__result
= std::move(*--__last
);
535 struct __copy_move_backward
<false, false, random_access_iterator_tag
>
537 template<typename _BI1
, typename _BI2
>
539 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
541 typename iterator_traits
<_BI1
>::difference_type __n
;
542 for (__n
= __last
- __first
; __n
> 0; --__n
)
543 *--__result
= *--__last
;
548 #if __cplusplus >= 201103L
550 struct __copy_move_backward
<true, false, random_access_iterator_tag
>
552 template<typename _BI1
, typename _BI2
>
554 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
556 typename iterator_traits
<_BI1
>::difference_type __n
;
557 for (__n
= __last
- __first
; __n
> 0; --__n
)
558 *--__result
= std::move(*--__last
);
564 template<bool _IsMove
>
565 struct __copy_move_backward
<_IsMove
, true, random_access_iterator_tag
>
567 template<typename _Tp
>
569 __copy_move_b(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
571 #if __cplusplus >= 201103L
572 // trivial types can have deleted assignment
573 static_assert( is_copy_assignable
<_Tp
>::value
,
574 "type is not assignable" );
576 const ptrdiff_t _Num
= __last
- __first
;
578 __builtin_memmove(__result
- _Num
, __first
, sizeof(_Tp
) * _Num
);
579 return __result
- _Num
;
583 template<bool _IsMove
, typename _BI1
, typename _BI2
>
585 __copy_move_backward_a(_BI1 __first
, _BI1 __last
, _BI2 __result
)
587 typedef typename iterator_traits
<_BI1
>::value_type _ValueType1
;
588 typedef typename iterator_traits
<_BI2
>::value_type _ValueType2
;
589 typedef typename iterator_traits
<_BI1
>::iterator_category _Category
;
590 const bool __simple
= (__is_trivial(_ValueType1
)
591 && __is_pointer
<_BI1
>::__value
592 && __is_pointer
<_BI2
>::__value
593 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
595 return std::__copy_move_backward
<_IsMove
, __simple
,
596 _Category
>::__copy_move_b(__first
,
601 template<bool _IsMove
, typename _BI1
, typename _BI2
>
603 __copy_move_backward_a2(_BI1 __first
, _BI1 __last
, _BI2 __result
)
605 return _BI2(std::__copy_move_backward_a
<_IsMove
>
606 (std::__niter_base(__first
), std::__niter_base(__last
),
607 std::__niter_base(__result
)));
611 * @brief Copies the range [first,last) into result.
612 * @ingroup mutating_algorithms
613 * @param __first A bidirectional iterator.
614 * @param __last A bidirectional iterator.
615 * @param __result A bidirectional iterator.
616 * @return result - (first - last)
618 * The function has the same effect as copy, but starts at the end of the
619 * range and works its way to the start, returning the start of the result.
620 * This inline function will boil down to a call to @c memmove whenever
621 * possible. Failing that, if random access iterators are passed, then the
622 * loop count will be known (and therefore a candidate for compiler
623 * optimizations such as unrolling).
625 * Result may not be in the range (first,last]. Use copy instead. Note
626 * that the start of the output range may overlap [first,last).
628 template<typename _BI1
, typename _BI2
>
630 copy_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
632 // concept requirements
633 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
634 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
635 __glibcxx_function_requires(_ConvertibleConcept
<
636 typename iterator_traits
<_BI1
>::value_type
,
637 typename iterator_traits
<_BI2
>::value_type
>)
638 __glibcxx_requires_valid_range(__first
, __last
);
640 return (std::__copy_move_backward_a2
<__is_move_iterator
<_BI1
>::__value
>
641 (std::__miter_base(__first
), std::__miter_base(__last
),
645 #if __cplusplus >= 201103L
647 * @brief Moves the range [first,last) into result.
648 * @ingroup mutating_algorithms
649 * @param __first A bidirectional iterator.
650 * @param __last A bidirectional iterator.
651 * @param __result A bidirectional iterator.
652 * @return result - (first - last)
654 * The function has the same effect as move, but starts at the end of the
655 * range and works its way to the start, returning the start of the result.
656 * This inline function will boil down to a call to @c memmove whenever
657 * possible. Failing that, if random access iterators are passed, then the
658 * loop count will be known (and therefore a candidate for compiler
659 * optimizations such as unrolling).
661 * Result may not be in the range (first,last]. Use move instead. Note
662 * that the start of the output range may overlap [first,last).
664 template<typename _BI1
, typename _BI2
>
666 move_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
668 // concept requirements
669 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
670 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
671 __glibcxx_function_requires(_ConvertibleConcept
<
672 typename iterator_traits
<_BI1
>::value_type
,
673 typename iterator_traits
<_BI2
>::value_type
>)
674 __glibcxx_requires_valid_range(__first
, __last
);
676 return std::__copy_move_backward_a2
<true>(std::__miter_base(__first
),
677 std::__miter_base(__last
),
681 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
683 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
686 template<typename _ForwardIterator
, typename _Tp
>
688 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, void>::__type
689 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
692 for (; __first
!= __last
; ++__first
)
696 template<typename _ForwardIterator
, typename _Tp
>
698 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, void>::__type
699 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
702 const _Tp __tmp
= __value
;
703 for (; __first
!= __last
; ++__first
)
707 // Specialization: for char types we can use memset.
708 template<typename _Tp
>
710 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, void>::__type
711 __fill_a(_Tp
* __first
, _Tp
* __last
, const _Tp
& __c
)
713 const _Tp __tmp
= __c
;
714 __builtin_memset(__first
, static_cast<unsigned char>(__tmp
),
719 * @brief Fills the range [first,last) with copies of value.
720 * @ingroup mutating_algorithms
721 * @param __first A forward iterator.
722 * @param __last A forward iterator.
723 * @param __value A reference-to-const of arbitrary type.
726 * This function fills a range with copies of the same value. For char
727 * types filling contiguous areas of memory, this becomes an inline call
728 * to @c memset or @c wmemset.
730 template<typename _ForwardIterator
, typename _Tp
>
732 fill(_ForwardIterator __first
, _ForwardIterator __last
, const _Tp
& __value
)
734 // concept requirements
735 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
737 __glibcxx_requires_valid_range(__first
, __last
);
739 std::__fill_a(std::__niter_base(__first
), std::__niter_base(__last
),
743 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
745 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
746 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
748 for (__decltype(__n
+ 0) __niter
= __n
;
749 __niter
> 0; --__niter
, ++__first
)
754 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
756 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
757 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
759 const _Tp __tmp
= __value
;
760 for (__decltype(__n
+ 0) __niter
= __n
;
761 __niter
> 0; --__niter
, ++__first
)
766 template<typename _Size
, typename _Tp
>
768 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, _Tp
*>::__type
769 __fill_n_a(_Tp
* __first
, _Size __n
, const _Tp
& __c
)
771 std::__fill_a(__first
, __first
+ __n
, __c
);
772 return __first
+ __n
;
776 * @brief Fills the range [first,first+n) with copies of value.
777 * @ingroup mutating_algorithms
778 * @param __first An output iterator.
779 * @param __n The count of copies to perform.
780 * @param __value A reference-to-const of arbitrary type.
781 * @return The iterator at first+n.
783 * This function fills a range with copies of the same value. For char
784 * types filling contiguous areas of memory, this becomes an inline call
785 * to @c memset or @ wmemset.
787 * _GLIBCXX_RESOLVE_LIB_DEFECTS
788 * DR 865. More algorithms that throw away information
790 template<typename _OI
, typename _Size
, typename _Tp
>
792 fill_n(_OI __first
, _Size __n
, const _Tp
& __value
)
794 // concept requirements
795 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
, _Tp
>)
797 return _OI(std::__fill_n_a(std::__niter_base(__first
), __n
, __value
));
800 template<bool _BoolType
>
803 template<typename _II1
, typename _II2
>
805 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
807 for (; __first1
!= __last1
; ++__first1
, ++__first2
)
808 if (!(*__first1
== *__first2
))
817 template<typename _Tp
>
819 equal(const _Tp
* __first1
, const _Tp
* __last1
, const _Tp
* __first2
)
821 return !__builtin_memcmp(__first1
, __first2
, sizeof(_Tp
)
822 * (__last1
- __first1
));
826 template<typename _II1
, typename _II2
>
828 __equal_aux(_II1 __first1
, _II1 __last1
, _II2 __first2
)
830 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
831 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
832 const bool __simple
= ((__is_integer
<_ValueType1
>::__value
833 || __is_pointer
<_ValueType1
>::__value
)
834 && __is_pointer
<_II1
>::__value
835 && __is_pointer
<_II2
>::__value
836 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
838 return std::__equal
<__simple
>::equal(__first1
, __last1
, __first2
);
841 template<typename
, typename
>
844 template<typename _II1
, typename _II2
>
846 __newlast1(_II1
, _II1 __last1
, _II2
, _II2
)
849 template<typename _II
>
851 __cnd2(_II __first
, _II __last
)
852 { return __first
!= __last
; }
856 struct __lc_rai
<random_access_iterator_tag
, random_access_iterator_tag
>
858 template<typename _RAI1
, typename _RAI2
>
860 __newlast1(_RAI1 __first1
, _RAI1 __last1
,
861 _RAI2 __first2
, _RAI2 __last2
)
863 const typename iterator_traits
<_RAI1
>::difference_type
864 __diff1
= __last1
- __first1
;
865 const typename iterator_traits
<_RAI2
>::difference_type
866 __diff2
= __last2
- __first2
;
867 return __diff2
< __diff1
? __first1
+ __diff2
: __last1
;
870 template<typename _RAI
>
876 template<typename _II1
, typename _II2
, typename _Compare
>
878 __lexicographical_compare_impl(_II1 __first1
, _II1 __last1
,
879 _II2 __first2
, _II2 __last2
,
882 typedef typename iterator_traits
<_II1
>::iterator_category _Category1
;
883 typedef typename iterator_traits
<_II2
>::iterator_category _Category2
;
884 typedef std::__lc_rai
<_Category1
, _Category2
> __rai_type
;
886 __last1
= __rai_type::__newlast1(__first1
, __last1
, __first2
, __last2
);
887 for (; __first1
!= __last1
&& __rai_type::__cnd2(__first2
, __last2
);
888 ++__first1
, ++__first2
)
890 if (__comp(__first1
, __first2
))
892 if (__comp(__first2
, __first1
))
895 return __first1
== __last1
&& __first2
!= __last2
;
898 template<bool _BoolType
>
899 struct __lexicographical_compare
901 template<typename _II1
, typename _II2
>
902 static bool __lc(_II1
, _II1
, _II2
, _II2
);
905 template<bool _BoolType
>
906 template<typename _II1
, typename _II2
>
908 __lexicographical_compare
<_BoolType
>::
909 __lc(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
911 return std::__lexicographical_compare_impl(__first1
, __last1
,
913 __gnu_cxx::__ops::__iter_less_iter());
917 struct __lexicographical_compare
<true>
919 template<typename _Tp
, typename _Up
>
921 __lc(const _Tp
* __first1
, const _Tp
* __last1
,
922 const _Up
* __first2
, const _Up
* __last2
)
924 const size_t __len1
= __last1
- __first1
;
925 const size_t __len2
= __last2
- __first2
;
926 const int __result
= __builtin_memcmp(__first1
, __first2
,
927 std::min(__len1
, __len2
));
928 return __result
!= 0 ? __result
< 0 : __len1
< __len2
;
932 template<typename _II1
, typename _II2
>
934 __lexicographical_compare_aux(_II1 __first1
, _II1 __last1
,
935 _II2 __first2
, _II2 __last2
)
937 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
938 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
939 const bool __simple
=
940 (__is_byte
<_ValueType1
>::__value
&& __is_byte
<_ValueType2
>::__value
941 && !__gnu_cxx::__numeric_traits
<_ValueType1
>::__is_signed
942 && !__gnu_cxx::__numeric_traits
<_ValueType2
>::__is_signed
943 && __is_pointer
<_II1
>::__value
944 && __is_pointer
<_II2
>::__value
);
946 return std::__lexicographical_compare
<__simple
>::__lc(__first1
, __last1
,
950 template<typename _ForwardIterator
, typename _Tp
, typename _Compare
>
952 __lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
953 const _Tp
& __val
, _Compare __comp
)
955 typedef typename iterator_traits
<_ForwardIterator
>::difference_type
958 _DistanceType __len
= std::distance(__first
, __last
);
962 _DistanceType __half
= __len
>> 1;
963 _ForwardIterator __middle
= __first
;
964 std::advance(__middle
, __half
);
965 if (__comp(__middle
, __val
))
969 __len
= __len
- __half
- 1;
978 * @brief Finds the first position in which @a val could be inserted
979 * without changing the ordering.
980 * @param __first An iterator.
981 * @param __last Another iterator.
982 * @param __val The search term.
983 * @return An iterator pointing to the first element <em>not less
984 * than</em> @a val, or end() if every element is less than
986 * @ingroup binary_search_algorithms
988 template<typename _ForwardIterator
, typename _Tp
>
989 inline _ForwardIterator
990 lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
993 // concept requirements
994 __glibcxx_function_requires(_ForwardIteratorConcept
<_ForwardIterator
>)
995 __glibcxx_function_requires(_LessThanOpConcept
<
996 typename iterator_traits
<_ForwardIterator
>::value_type
, _Tp
>)
997 __glibcxx_requires_partitioned_lower(__first
, __last
, __val
);
999 return std::__lower_bound(__first
, __last
, __val
,
1000 __gnu_cxx::__ops::__iter_less_val());
1003 /// This is a helper function for the sort routines and for random.tcc.
1004 // Precondition: __n > 0.
1005 inline _GLIBCXX_CONSTEXPR
int
1007 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1009 inline _GLIBCXX_CONSTEXPR
unsigned
1011 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1013 inline _GLIBCXX_CONSTEXPR
long
1015 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1017 inline _GLIBCXX_CONSTEXPR
unsigned long
1018 __lg(unsigned long __n
)
1019 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1021 inline _GLIBCXX_CONSTEXPR
long long
1023 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1025 inline _GLIBCXX_CONSTEXPR
unsigned long long
1026 __lg(unsigned long long __n
)
1027 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1029 _GLIBCXX_END_NAMESPACE_VERSION
1031 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1034 * @brief Tests a range for element-wise equality.
1035 * @ingroup non_mutating_algorithms
1036 * @param __first1 An input iterator.
1037 * @param __last1 An input iterator.
1038 * @param __first2 An input iterator.
1039 * @return A boolean true or false.
1041 * This compares the elements of two ranges using @c == and returns true or
1042 * false depending on whether all of the corresponding elements of the
1045 template<typename _II1
, typename _II2
>
1047 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
1049 // concept requirements
1050 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1051 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1052 __glibcxx_function_requires(_EqualOpConcept
<
1053 typename iterator_traits
<_II1
>::value_type
,
1054 typename iterator_traits
<_II2
>::value_type
>)
1055 __glibcxx_requires_valid_range(__first1
, __last1
);
1057 return std::__equal_aux(std::__niter_base(__first1
),
1058 std::__niter_base(__last1
),
1059 std::__niter_base(__first2
));
1063 * @brief Tests a range for element-wise equality.
1064 * @ingroup non_mutating_algorithms
1065 * @param __first1 An input iterator.
1066 * @param __last1 An input iterator.
1067 * @param __first2 An input iterator.
1068 * @param __binary_pred A binary predicate @link functors
1070 * @return A boolean true or false.
1072 * This compares the elements of two ranges using the binary_pred
1073 * parameter, and returns true or
1074 * false depending on whether all of the corresponding elements of the
1077 template<typename _IIter1
, typename _IIter2
, typename _BinaryPredicate
>
1079 equal(_IIter1 __first1
, _IIter1 __last1
,
1080 _IIter2 __first2
, _BinaryPredicate __binary_pred
)
1082 // concept requirements
1083 __glibcxx_function_requires(_InputIteratorConcept
<_IIter1
>)
1084 __glibcxx_function_requires(_InputIteratorConcept
<_IIter2
>)
1085 __glibcxx_requires_valid_range(__first1
, __last1
);
1087 for (; __first1
!= __last1
; ++__first1
, ++__first2
)
1088 if (!bool(__binary_pred(*__first1
, *__first2
)))
1093 #if __cplusplus > 201103L
1095 * @brief Tests a range for element-wise equality.
1096 * @ingroup non_mutating_algorithms
1097 * @param __first1 An input iterator.
1098 * @param __last1 An input iterator.
1099 * @param __first2 An input iterator.
1100 * @param __last2 An input iterator.
1101 * @return A boolean true or false.
1103 * This compares the elements of two ranges using @c == and returns true or
1104 * false depending on whether all of the corresponding elements of the
1107 template<typename _II1
, typename _II2
>
1109 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
1111 // concept requirements
1112 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1113 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1114 __glibcxx_function_requires(_EqualOpConcept
<
1115 typename iterator_traits
<_II1
>::value_type
,
1116 typename iterator_traits
<_II2
>::value_type
>)
1117 __glibcxx_requires_valid_range(__first1
, __last1
);
1118 __glibcxx_requires_valid_range(__first2
, __last2
);
1120 using _RATag
= random_access_iterator_tag
;
1121 using _Cat1
= typename iterator_traits
<_II1
>::iterator_category
;
1122 using _Cat2
= typename iterator_traits
<_II2
>::iterator_category
;
1123 using _RAIters
= __and_
<is_same
<_Cat1
, _RATag
>, is_same
<_Cat2
, _RATag
>>;
1126 auto __d1
= std::distance(__first1
, __last1
);
1127 auto __d2
= std::distance(__first2
, __last2
);
1130 return _GLIBCXX_STD_A::equal(__first1
, __last1
, __first2
);
1133 for (; __first1
!= __last1
&& __first2
!= __last2
; ++__first1
, ++__first2
)
1134 if (!(*__first1
== *__first2
))
1136 return __first1
== __last1
&& __first2
== __last2
;
1140 * @brief Tests a range for element-wise equality.
1141 * @ingroup non_mutating_algorithms
1142 * @param __first1 An input iterator.
1143 * @param __last1 An input iterator.
1144 * @param __first2 An input iterator.
1145 * @param __last2 An input iterator.
1146 * @param __binary_pred A binary predicate @link functors
1148 * @return A boolean true or false.
1150 * This compares the elements of two ranges using the binary_pred
1151 * parameter, and returns true or
1152 * false depending on whether all of the corresponding elements of the
1155 template<typename _IIter1
, typename _IIter2
, typename _BinaryPredicate
>
1157 equal(_IIter1 __first1
, _IIter1 __last1
,
1158 _IIter2 __first2
, _IIter2 __last2
, _BinaryPredicate __binary_pred
)
1160 // concept requirements
1161 __glibcxx_function_requires(_InputIteratorConcept
<_IIter1
>)
1162 __glibcxx_function_requires(_InputIteratorConcept
<_IIter2
>)
1163 __glibcxx_requires_valid_range(__first1
, __last1
);
1164 __glibcxx_requires_valid_range(__first2
, __last2
);
1166 using _RATag
= random_access_iterator_tag
;
1167 using _Cat1
= typename iterator_traits
<_IIter1
>::iterator_category
;
1168 using _Cat2
= typename iterator_traits
<_IIter2
>::iterator_category
;
1169 using _RAIters
= __and_
<is_same
<_Cat1
, _RATag
>, is_same
<_Cat2
, _RATag
>>;
1172 auto __d1
= std::distance(__first1
, __last1
);
1173 auto __d2
= std::distance(__first2
, __last2
);
1176 return _GLIBCXX_STD_A::equal(__first1
, __last1
, __first2
,
1180 for (; __first1
!= __last1
&& __first2
!= __last2
; ++__first1
, ++__first2
)
1181 if (!bool(__binary_pred(*__first1
, *__first2
)))
1183 return __first1
== __last1
&& __first2
== __last2
;
1188 * @brief Performs @b dictionary comparison on ranges.
1189 * @ingroup sorting_algorithms
1190 * @param __first1 An input iterator.
1191 * @param __last1 An input iterator.
1192 * @param __first2 An input iterator.
1193 * @param __last2 An input iterator.
1194 * @return A boolean true or false.
1196 * <em>Returns true if the sequence of elements defined by the range
1197 * [first1,last1) is lexicographically less than the sequence of elements
1198 * defined by the range [first2,last2). Returns false otherwise.</em>
1199 * (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
1200 * then this is an inline call to @c memcmp.
1202 template<typename _II1
, typename _II2
>
1204 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1205 _II2 __first2
, _II2 __last2
)
1207 #ifdef _GLIBCXX_CONCEPT_CHECKS
1208 // concept requirements
1209 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
1210 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
1212 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1213 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1214 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType1
, _ValueType2
>)
1215 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType2
, _ValueType1
>)
1216 __glibcxx_requires_valid_range(__first1
, __last1
);
1217 __glibcxx_requires_valid_range(__first2
, __last2
);
1219 return std::__lexicographical_compare_aux(std::__niter_base(__first1
),
1220 std::__niter_base(__last1
),
1221 std::__niter_base(__first2
),
1222 std::__niter_base(__last2
));
1226 * @brief Performs @b dictionary comparison on ranges.
1227 * @ingroup sorting_algorithms
1228 * @param __first1 An input iterator.
1229 * @param __last1 An input iterator.
1230 * @param __first2 An input iterator.
1231 * @param __last2 An input iterator.
1232 * @param __comp A @link comparison_functors comparison functor@endlink.
1233 * @return A boolean true or false.
1235 * The same as the four-parameter @c lexicographical_compare, but uses the
1236 * comp parameter instead of @c <.
1238 template<typename _II1
, typename _II2
, typename _Compare
>
1240 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1241 _II2 __first2
, _II2 __last2
, _Compare __comp
)
1243 // concept requirements
1244 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1245 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1246 __glibcxx_requires_valid_range(__first1
, __last1
);
1247 __glibcxx_requires_valid_range(__first2
, __last2
);
1249 return std::__lexicographical_compare_impl
1250 (__first1
, __last1
, __first2
, __last2
,
1251 __gnu_cxx::__ops::__iter_comp_iter(__comp
));
1254 template<typename _InputIterator1
, typename _InputIterator2
,
1255 typename _BinaryPredicate
>
1256 pair
<_InputIterator1
, _InputIterator2
>
1257 __mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1258 _InputIterator2 __first2
, _BinaryPredicate __binary_pred
)
1260 while (__first1
!= __last1
&& __binary_pred(__first1
, __first2
))
1265 return pair
<_InputIterator1
, _InputIterator2
>(__first1
, __first2
);
1269 * @brief Finds the places in ranges which don't match.
1270 * @ingroup non_mutating_algorithms
1271 * @param __first1 An input iterator.
1272 * @param __last1 An input iterator.
1273 * @param __first2 An input iterator.
1274 * @return A pair of iterators pointing to the first mismatch.
1276 * This compares the elements of two ranges using @c == and returns a pair
1277 * of iterators. The first iterator points into the first range, the
1278 * second iterator points into the second range, and the elements pointed
1279 * to by the iterators are not equal.
1281 template<typename _InputIterator1
, typename _InputIterator2
>
1282 inline pair
<_InputIterator1
, _InputIterator2
>
1283 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1284 _InputIterator2 __first2
)
1286 // concept requirements
1287 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1288 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1289 __glibcxx_function_requires(_EqualOpConcept
<
1290 typename iterator_traits
<_InputIterator1
>::value_type
,
1291 typename iterator_traits
<_InputIterator2
>::value_type
>)
1292 __glibcxx_requires_valid_range(__first1
, __last1
);
1294 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
,
1295 __gnu_cxx::__ops::__iter_equal_to_iter());
1299 * @brief Finds the places in ranges which don't match.
1300 * @ingroup non_mutating_algorithms
1301 * @param __first1 An input iterator.
1302 * @param __last1 An input iterator.
1303 * @param __first2 An input iterator.
1304 * @param __binary_pred A binary predicate @link functors
1306 * @return A pair of iterators pointing to the first mismatch.
1308 * This compares the elements of two ranges using the binary_pred
1309 * parameter, and returns a pair
1310 * of iterators. The first iterator points into the first range, the
1311 * second iterator points into the second range, and the elements pointed
1312 * to by the iterators are not equal.
1314 template<typename _InputIterator1
, typename _InputIterator2
,
1315 typename _BinaryPredicate
>
1316 inline pair
<_InputIterator1
, _InputIterator2
>
1317 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1318 _InputIterator2 __first2
, _BinaryPredicate __binary_pred
)
1320 // concept requirements
1321 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1322 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1323 __glibcxx_requires_valid_range(__first1
, __last1
);
1325 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
,
1326 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred
));
1329 #if __cplusplus > 201103L
1331 template<typename _InputIterator1
, typename _InputIterator2
,
1332 typename _BinaryPredicate
>
1333 pair
<_InputIterator1
, _InputIterator2
>
1334 __mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1335 _InputIterator2 __first2
, _InputIterator2 __last2
,
1336 _BinaryPredicate __binary_pred
)
1338 while (__first1
!= __last1
&& __first2
!= __last2
1339 && __binary_pred(__first1
, __first2
))
1344 return pair
<_InputIterator1
, _InputIterator2
>(__first1
, __first2
);
1348 * @brief Finds the places in ranges which don't match.
1349 * @ingroup non_mutating_algorithms
1350 * @param __first1 An input iterator.
1351 * @param __last1 An input iterator.
1352 * @param __first2 An input iterator.
1353 * @param __last2 An input iterator.
1354 * @return A pair of iterators pointing to the first mismatch.
1356 * This compares the elements of two ranges using @c == and returns a pair
1357 * of iterators. The first iterator points into the first range, the
1358 * second iterator points into the second range, and the elements pointed
1359 * to by the iterators are not equal.
1361 template<typename _InputIterator1
, typename _InputIterator2
>
1362 inline pair
<_InputIterator1
, _InputIterator2
>
1363 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1364 _InputIterator2 __first2
, _InputIterator2 __last2
)
1366 // concept requirements
1367 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1368 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1369 __glibcxx_function_requires(_EqualOpConcept
<
1370 typename iterator_traits
<_InputIterator1
>::value_type
,
1371 typename iterator_traits
<_InputIterator2
>::value_type
>)
1372 __glibcxx_requires_valid_range(__first1
, __last1
);
1373 __glibcxx_requires_valid_range(__first2
, __last2
);
1375 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
, __last2
,
1376 __gnu_cxx::__ops::__iter_equal_to_iter());
1380 * @brief Finds the places in ranges which don't match.
1381 * @ingroup non_mutating_algorithms
1382 * @param __first1 An input iterator.
1383 * @param __last1 An input iterator.
1384 * @param __first2 An input iterator.
1385 * @param __last2 An input iterator.
1386 * @param __binary_pred A binary predicate @link functors
1388 * @return A pair of iterators pointing to the first mismatch.
1390 * This compares the elements of two ranges using the binary_pred
1391 * parameter, and returns a pair
1392 * of iterators. The first iterator points into the first range, the
1393 * second iterator points into the second range, and the elements pointed
1394 * to by the iterators are not equal.
1396 template<typename _InputIterator1
, typename _InputIterator2
,
1397 typename _BinaryPredicate
>
1398 inline pair
<_InputIterator1
, _InputIterator2
>
1399 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1400 _InputIterator2 __first2
, _InputIterator2 __last2
,
1401 _BinaryPredicate __binary_pred
)
1403 // concept requirements
1404 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1405 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1406 __glibcxx_requires_valid_range(__first1
, __last1
);
1407 __glibcxx_requires_valid_range(__first2
, __last2
);
1409 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
, __last2
,
1410 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred
));
1414 _GLIBCXX_END_NAMESPACE_ALGO
1417 // NB: This file is included within many other C++ includes, as a way
1418 // of getting the base algorithms. So, make sure that parallel bits
1419 // come in too if requested.
1420 #ifdef _GLIBCXX_PARALLEL
1421 # include <parallel/algobase.h>