1 // Core algorithmic facilities -*- C++ -*-
3 // Copyright (C) 2001-2015 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
, (void)++__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
>
195 min(const _Tp
& __a
, const _Tp
& __b
)
197 // concept requirements
198 __glibcxx_function_requires(_LessThanComparableConcept
<_Tp
>)
199 //return __b < __a ? __b : __a;
206 * @brief This does what you think it does.
207 * @ingroup sorting_algorithms
208 * @param __a A thing of arbitrary type.
209 * @param __b Another thing of arbitrary type.
210 * @return The greater of the parameters.
212 * This is the simple classic generic implementation. It will work on
213 * temporary expressions, since they are only evaluated once, unlike a
214 * preprocessor macro.
216 template<typename _Tp
>
219 max(const _Tp
& __a
, const _Tp
& __b
)
221 // concept requirements
222 __glibcxx_function_requires(_LessThanComparableConcept
<_Tp
>)
223 //return __a < __b ? __b : __a;
230 * @brief This does what you think it does.
231 * @ingroup sorting_algorithms
232 * @param __a A thing of arbitrary type.
233 * @param __b Another thing of arbitrary type.
234 * @param __comp A @link comparison_functors comparison functor@endlink.
235 * @return The lesser of the parameters.
237 * This will work on temporary expressions, since they are only evaluated
238 * once, unlike a preprocessor macro.
240 template<typename _Tp
, typename _Compare
>
243 min(const _Tp
& __a
, const _Tp
& __b
, _Compare __comp
)
245 //return __comp(__b, __a) ? __b : __a;
246 if (__comp(__b
, __a
))
252 * @brief This does what you think it does.
253 * @ingroup sorting_algorithms
254 * @param __a A thing of arbitrary type.
255 * @param __b Another thing of arbitrary type.
256 * @param __comp A @link comparison_functors comparison functor@endlink.
257 * @return The greater of the parameters.
259 * This will work on temporary expressions, since they are only evaluated
260 * once, unlike a preprocessor macro.
262 template<typename _Tp
, typename _Compare
>
265 max(const _Tp
& __a
, const _Tp
& __b
, _Compare __comp
)
267 //return __comp(__a, __b) ? __b : __a;
268 if (__comp(__a
, __b
))
273 // Fallback implementation of the function in bits/stl_iterator.h used to
274 // remove the __normal_iterator wrapper. See copy, fill, ...
275 template<typename _Iterator
>
277 __niter_base(_Iterator __it
)
280 // All of these auxiliary structs serve two purposes. (1) Replace
281 // calls to copy with memmove whenever possible. (Memmove, not memcpy,
282 // because the input and output ranges are permitted to overlap.)
283 // (2) If we're using random access iterators, then write the loop as
284 // a for loop with an explicit count.
286 template<bool, bool, typename
>
289 template<typename _II
, typename _OI
>
291 __copy_m(_II __first
, _II __last
, _OI __result
)
293 for (; __first
!= __last
; ++__result
, (void)++__first
)
294 *__result
= *__first
;
299 #if __cplusplus >= 201103L
300 template<typename _Category
>
301 struct __copy_move
<true, false, _Category
>
303 template<typename _II
, typename _OI
>
305 __copy_m(_II __first
, _II __last
, _OI __result
)
307 for (; __first
!= __last
; ++__result
, (void)++__first
)
308 *__result
= std::move(*__first
);
315 struct __copy_move
<false, false, random_access_iterator_tag
>
317 template<typename _II
, typename _OI
>
319 __copy_m(_II __first
, _II __last
, _OI __result
)
321 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
322 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
324 *__result
= *__first
;
332 #if __cplusplus >= 201103L
334 struct __copy_move
<true, false, random_access_iterator_tag
>
336 template<typename _II
, typename _OI
>
338 __copy_m(_II __first
, _II __last
, _OI __result
)
340 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
341 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
343 *__result
= std::move(*__first
);
352 template<bool _IsMove
>
353 struct __copy_move
<_IsMove
, true, random_access_iterator_tag
>
355 template<typename _Tp
>
357 __copy_m(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
359 #if __cplusplus >= 201103L
360 // trivial types can have deleted assignment
361 static_assert( is_copy_assignable
<_Tp
>::value
,
362 "type is not assignable" );
364 const ptrdiff_t _Num
= __last
- __first
;
366 __builtin_memmove(__result
, __first
, sizeof(_Tp
) * _Num
);
367 return __result
+ _Num
;
371 template<bool _IsMove
, typename _II
, typename _OI
>
373 __copy_move_a(_II __first
, _II __last
, _OI __result
)
375 typedef typename iterator_traits
<_II
>::value_type _ValueTypeI
;
376 typedef typename iterator_traits
<_OI
>::value_type _ValueTypeO
;
377 typedef typename iterator_traits
<_II
>::iterator_category _Category
;
378 const bool __simple
= (__is_trivial(_ValueTypeI
)
379 && __is_pointer
<_II
>::__value
380 && __is_pointer
<_OI
>::__value
381 && __are_same
<_ValueTypeI
, _ValueTypeO
>::__value
);
383 return std::__copy_move
<_IsMove
, __simple
,
384 _Category
>::__copy_m(__first
, __last
, __result
);
387 // Helpers for streambuf iterators (either istream or ostream).
388 // NB: avoid including <iosfwd>, relatively large.
389 template<typename _CharT
>
392 template<typename _CharT
, typename _Traits
>
393 class istreambuf_iterator
;
395 template<typename _CharT
, typename _Traits
>
396 class ostreambuf_iterator
;
398 template<bool _IsMove
, typename _CharT
>
399 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
400 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> > >::__type
401 __copy_move_a2(_CharT
*, _CharT
*,
402 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
404 template<bool _IsMove
, typename _CharT
>
405 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
406 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> > >::__type
407 __copy_move_a2(const _CharT
*, const _CharT
*,
408 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
410 template<bool _IsMove
, typename _CharT
>
411 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
413 __copy_move_a2(istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >,
414 istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >, _CharT
*);
416 template<bool _IsMove
, typename _II
, typename _OI
>
418 __copy_move_a2(_II __first
, _II __last
, _OI __result
)
420 return _OI(std::__copy_move_a
<_IsMove
>(std::__niter_base(__first
),
421 std::__niter_base(__last
),
422 std::__niter_base(__result
)));
426 * @brief Copies the range [first,last) into result.
427 * @ingroup mutating_algorithms
428 * @param __first An input iterator.
429 * @param __last An input iterator.
430 * @param __result An output iterator.
431 * @return result + (first - last)
433 * This inline function will boil down to a call to @c memmove whenever
434 * possible. Failing that, if random access iterators are passed, then the
435 * loop count will be known (and therefore a candidate for compiler
436 * optimizations such as unrolling). Result may not be contained within
437 * [first,last); the copy_backward function should be used instead.
439 * Note that the end of the output range is permitted to be contained
440 * within [first,last).
442 template<typename _II
, typename _OI
>
444 copy(_II __first
, _II __last
, _OI __result
)
446 // concept requirements
447 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
448 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
449 typename iterator_traits
<_II
>::value_type
>)
450 __glibcxx_requires_valid_range(__first
, __last
);
452 return (std::__copy_move_a2
<__is_move_iterator
<_II
>::__value
>
453 (std::__miter_base(__first
), std::__miter_base(__last
),
457 #if __cplusplus >= 201103L
459 * @brief Moves the range [first,last) into result.
460 * @ingroup mutating_algorithms
461 * @param __first An input iterator.
462 * @param __last An input iterator.
463 * @param __result An output iterator.
464 * @return result + (first - last)
466 * This inline function will boil down to a call to @c memmove whenever
467 * possible. Failing that, if random access iterators are passed, then the
468 * loop count will be known (and therefore a candidate for compiler
469 * optimizations such as unrolling). Result may not be contained within
470 * [first,last); the move_backward function should be used instead.
472 * Note that the end of the output range is permitted to be contained
473 * within [first,last).
475 template<typename _II
, typename _OI
>
477 move(_II __first
, _II __last
, _OI __result
)
479 // concept requirements
480 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
481 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
482 typename iterator_traits
<_II
>::value_type
>)
483 __glibcxx_requires_valid_range(__first
, __last
);
485 return std::__copy_move_a2
<true>(std::__miter_base(__first
),
486 std::__miter_base(__last
), __result
);
489 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
491 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
494 template<bool, bool, typename
>
495 struct __copy_move_backward
497 template<typename _BI1
, typename _BI2
>
499 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
501 while (__first
!= __last
)
502 *--__result
= *--__last
;
507 #if __cplusplus >= 201103L
508 template<typename _Category
>
509 struct __copy_move_backward
<true, false, _Category
>
511 template<typename _BI1
, typename _BI2
>
513 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
515 while (__first
!= __last
)
516 *--__result
= std::move(*--__last
);
523 struct __copy_move_backward
<false, false, random_access_iterator_tag
>
525 template<typename _BI1
, typename _BI2
>
527 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
529 typename iterator_traits
<_BI1
>::difference_type __n
;
530 for (__n
= __last
- __first
; __n
> 0; --__n
)
531 *--__result
= *--__last
;
536 #if __cplusplus >= 201103L
538 struct __copy_move_backward
<true, false, random_access_iterator_tag
>
540 template<typename _BI1
, typename _BI2
>
542 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
544 typename iterator_traits
<_BI1
>::difference_type __n
;
545 for (__n
= __last
- __first
; __n
> 0; --__n
)
546 *--__result
= std::move(*--__last
);
552 template<bool _IsMove
>
553 struct __copy_move_backward
<_IsMove
, true, random_access_iterator_tag
>
555 template<typename _Tp
>
557 __copy_move_b(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
559 #if __cplusplus >= 201103L
560 // trivial types can have deleted assignment
561 static_assert( is_copy_assignable
<_Tp
>::value
,
562 "type is not assignable" );
564 const ptrdiff_t _Num
= __last
- __first
;
566 __builtin_memmove(__result
- _Num
, __first
, sizeof(_Tp
) * _Num
);
567 return __result
- _Num
;
571 template<bool _IsMove
, typename _BI1
, typename _BI2
>
573 __copy_move_backward_a(_BI1 __first
, _BI1 __last
, _BI2 __result
)
575 typedef typename iterator_traits
<_BI1
>::value_type _ValueType1
;
576 typedef typename iterator_traits
<_BI2
>::value_type _ValueType2
;
577 typedef typename iterator_traits
<_BI1
>::iterator_category _Category
;
578 const bool __simple
= (__is_trivial(_ValueType1
)
579 && __is_pointer
<_BI1
>::__value
580 && __is_pointer
<_BI2
>::__value
581 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
583 return std::__copy_move_backward
<_IsMove
, __simple
,
584 _Category
>::__copy_move_b(__first
,
589 template<bool _IsMove
, typename _BI1
, typename _BI2
>
591 __copy_move_backward_a2(_BI1 __first
, _BI1 __last
, _BI2 __result
)
593 return _BI2(std::__copy_move_backward_a
<_IsMove
>
594 (std::__niter_base(__first
), std::__niter_base(__last
),
595 std::__niter_base(__result
)));
599 * @brief Copies the range [first,last) into result.
600 * @ingroup mutating_algorithms
601 * @param __first A bidirectional iterator.
602 * @param __last A bidirectional iterator.
603 * @param __result A bidirectional iterator.
604 * @return result - (first - last)
606 * The function has the same effect as copy, but starts at the end of the
607 * range and works its way to the start, returning the start of the result.
608 * This inline function will boil down to a call to @c memmove whenever
609 * possible. Failing that, if random access iterators are passed, then the
610 * loop count will be known (and therefore a candidate for compiler
611 * optimizations such as unrolling).
613 * Result may not be in the range (first,last]. Use copy instead. Note
614 * that the start of the output range may overlap [first,last).
616 template<typename _BI1
, typename _BI2
>
618 copy_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
620 // concept requirements
621 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
622 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
623 __glibcxx_function_requires(_ConvertibleConcept
<
624 typename iterator_traits
<_BI1
>::value_type
,
625 typename iterator_traits
<_BI2
>::value_type
>)
626 __glibcxx_requires_valid_range(__first
, __last
);
628 return (std::__copy_move_backward_a2
<__is_move_iterator
<_BI1
>::__value
>
629 (std::__miter_base(__first
), std::__miter_base(__last
),
633 #if __cplusplus >= 201103L
635 * @brief Moves the range [first,last) into result.
636 * @ingroup mutating_algorithms
637 * @param __first A bidirectional iterator.
638 * @param __last A bidirectional iterator.
639 * @param __result A bidirectional iterator.
640 * @return result - (first - last)
642 * The function has the same effect as move, but starts at the end of the
643 * range and works its way to the start, returning the start of the result.
644 * This inline function will boil down to a call to @c memmove whenever
645 * possible. Failing that, if random access iterators are passed, then the
646 * loop count will be known (and therefore a candidate for compiler
647 * optimizations such as unrolling).
649 * Result may not be in the range (first,last]. Use move instead. Note
650 * that the start of the output range may overlap [first,last).
652 template<typename _BI1
, typename _BI2
>
654 move_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
656 // concept requirements
657 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
658 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
659 __glibcxx_function_requires(_ConvertibleConcept
<
660 typename iterator_traits
<_BI1
>::value_type
,
661 typename iterator_traits
<_BI2
>::value_type
>)
662 __glibcxx_requires_valid_range(__first
, __last
);
664 return std::__copy_move_backward_a2
<true>(std::__miter_base(__first
),
665 std::__miter_base(__last
),
669 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
671 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
674 template<typename _ForwardIterator
, typename _Tp
>
676 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, void>::__type
677 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
680 for (; __first
!= __last
; ++__first
)
684 template<typename _ForwardIterator
, typename _Tp
>
686 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, void>::__type
687 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
690 const _Tp __tmp
= __value
;
691 for (; __first
!= __last
; ++__first
)
695 // Specialization: for char types we can use memset.
696 template<typename _Tp
>
698 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, void>::__type
699 __fill_a(_Tp
* __first
, _Tp
* __last
, const _Tp
& __c
)
701 const _Tp __tmp
= __c
;
702 if (const size_t __len
= __last
- __first
)
703 __builtin_memset(__first
, static_cast<unsigned char>(__tmp
), __len
);
707 * @brief Fills the range [first,last) with copies of value.
708 * @ingroup mutating_algorithms
709 * @param __first A forward iterator.
710 * @param __last A forward iterator.
711 * @param __value A reference-to-const of arbitrary type.
714 * This function fills a range with copies of the same value. For char
715 * types filling contiguous areas of memory, this becomes an inline call
716 * to @c memset or @c wmemset.
718 template<typename _ForwardIterator
, typename _Tp
>
720 fill(_ForwardIterator __first
, _ForwardIterator __last
, const _Tp
& __value
)
722 // concept requirements
723 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
725 __glibcxx_requires_valid_range(__first
, __last
);
727 std::__fill_a(std::__niter_base(__first
), std::__niter_base(__last
),
731 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
733 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
734 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
736 for (__decltype(__n
+ 0) __niter
= __n
;
737 __niter
> 0; --__niter
, ++__first
)
742 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
744 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
745 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
747 const _Tp __tmp
= __value
;
748 for (__decltype(__n
+ 0) __niter
= __n
;
749 __niter
> 0; --__niter
, ++__first
)
754 template<typename _Size
, typename _Tp
>
756 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, _Tp
*>::__type
757 __fill_n_a(_Tp
* __first
, _Size __n
, const _Tp
& __c
)
759 std::__fill_a(__first
, __first
+ __n
, __c
);
760 return __first
+ __n
;
764 * @brief Fills the range [first,first+n) with copies of value.
765 * @ingroup mutating_algorithms
766 * @param __first An output iterator.
767 * @param __n The count of copies to perform.
768 * @param __value A reference-to-const of arbitrary type.
769 * @return The iterator at first+n.
771 * This function fills a range with copies of the same value. For char
772 * types filling contiguous areas of memory, this becomes an inline call
773 * to @c memset or @ wmemset.
775 * _GLIBCXX_RESOLVE_LIB_DEFECTS
776 * DR 865. More algorithms that throw away information
778 template<typename _OI
, typename _Size
, typename _Tp
>
780 fill_n(_OI __first
, _Size __n
, const _Tp
& __value
)
782 // concept requirements
783 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
, _Tp
>)
785 return _OI(std::__fill_n_a(std::__niter_base(__first
), __n
, __value
));
788 template<bool _BoolType
>
791 template<typename _II1
, typename _II2
>
793 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
795 for (; __first1
!= __last1
; ++__first1
, (void)++__first2
)
796 if (!(*__first1
== *__first2
))
805 template<typename _Tp
>
807 equal(const _Tp
* __first1
, const _Tp
* __last1
, const _Tp
* __first2
)
809 if (const size_t __len
= (__last1
- __first1
))
810 return !__builtin_memcmp(__first1
, __first2
, sizeof(_Tp
) * __len
);
815 template<typename _II1
, typename _II2
>
817 __equal_aux(_II1 __first1
, _II1 __last1
, _II2 __first2
)
819 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
820 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
821 const bool __simple
= ((__is_integer
<_ValueType1
>::__value
822 || __is_pointer
<_ValueType1
>::__value
)
823 && __is_pointer
<_II1
>::__value
824 && __is_pointer
<_II2
>::__value
825 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
827 return std::__equal
<__simple
>::equal(__first1
, __last1
, __first2
);
830 template<typename
, typename
>
833 template<typename _II1
, typename _II2
>
835 __newlast1(_II1
, _II1 __last1
, _II2
, _II2
)
838 template<typename _II
>
840 __cnd2(_II __first
, _II __last
)
841 { return __first
!= __last
; }
845 struct __lc_rai
<random_access_iterator_tag
, random_access_iterator_tag
>
847 template<typename _RAI1
, typename _RAI2
>
849 __newlast1(_RAI1 __first1
, _RAI1 __last1
,
850 _RAI2 __first2
, _RAI2 __last2
)
852 const typename iterator_traits
<_RAI1
>::difference_type
853 __diff1
= __last1
- __first1
;
854 const typename iterator_traits
<_RAI2
>::difference_type
855 __diff2
= __last2
- __first2
;
856 return __diff2
< __diff1
? __first1
+ __diff2
: __last1
;
859 template<typename _RAI
>
865 template<typename _II1
, typename _II2
, typename _Compare
>
867 __lexicographical_compare_impl(_II1 __first1
, _II1 __last1
,
868 _II2 __first2
, _II2 __last2
,
871 typedef typename iterator_traits
<_II1
>::iterator_category _Category1
;
872 typedef typename iterator_traits
<_II2
>::iterator_category _Category2
;
873 typedef std::__lc_rai
<_Category1
, _Category2
> __rai_type
;
875 __last1
= __rai_type::__newlast1(__first1
, __last1
, __first2
, __last2
);
876 for (; __first1
!= __last1
&& __rai_type::__cnd2(__first2
, __last2
);
877 ++__first1
, (void)++__first2
)
879 if (__comp(__first1
, __first2
))
881 if (__comp(__first2
, __first1
))
884 return __first1
== __last1
&& __first2
!= __last2
;
887 template<bool _BoolType
>
888 struct __lexicographical_compare
890 template<typename _II1
, typename _II2
>
891 static bool __lc(_II1
, _II1
, _II2
, _II2
);
894 template<bool _BoolType
>
895 template<typename _II1
, typename _II2
>
897 __lexicographical_compare
<_BoolType
>::
898 __lc(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
900 return std::__lexicographical_compare_impl(__first1
, __last1
,
902 __gnu_cxx::__ops::__iter_less_iter());
906 struct __lexicographical_compare
<true>
908 template<typename _Tp
, typename _Up
>
910 __lc(const _Tp
* __first1
, const _Tp
* __last1
,
911 const _Up
* __first2
, const _Up
* __last2
)
913 const size_t __len1
= __last1
- __first1
;
914 const size_t __len2
= __last2
- __first2
;
915 if (const size_t __len
= std::min(__len1
, __len2
))
916 if (int __result
= __builtin_memcmp(__first1
, __first2
, __len
))
918 return __len1
< __len2
;
922 template<typename _II1
, typename _II2
>
924 __lexicographical_compare_aux(_II1 __first1
, _II1 __last1
,
925 _II2 __first2
, _II2 __last2
)
927 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
928 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
929 const bool __simple
=
930 (__is_byte
<_ValueType1
>::__value
&& __is_byte
<_ValueType2
>::__value
931 && !__gnu_cxx::__numeric_traits
<_ValueType1
>::__is_signed
932 && !__gnu_cxx::__numeric_traits
<_ValueType2
>::__is_signed
933 && __is_pointer
<_II1
>::__value
934 && __is_pointer
<_II2
>::__value
);
936 return std::__lexicographical_compare
<__simple
>::__lc(__first1
, __last1
,
940 template<typename _ForwardIterator
, typename _Tp
, typename _Compare
>
942 __lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
943 const _Tp
& __val
, _Compare __comp
)
945 typedef typename iterator_traits
<_ForwardIterator
>::difference_type
948 _DistanceType __len
= std::distance(__first
, __last
);
952 _DistanceType __half
= __len
>> 1;
953 _ForwardIterator __middle
= __first
;
954 std::advance(__middle
, __half
);
955 if (__comp(__middle
, __val
))
959 __len
= __len
- __half
- 1;
968 * @brief Finds the first position in which @a val could be inserted
969 * without changing the ordering.
970 * @param __first An iterator.
971 * @param __last Another iterator.
972 * @param __val The search term.
973 * @return An iterator pointing to the first element <em>not less
974 * than</em> @a val, or end() if every element is less than
976 * @ingroup binary_search_algorithms
978 template<typename _ForwardIterator
, typename _Tp
>
979 inline _ForwardIterator
980 lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
983 // concept requirements
984 __glibcxx_function_requires(_ForwardIteratorConcept
<_ForwardIterator
>)
985 __glibcxx_function_requires(_LessThanOpConcept
<
986 typename iterator_traits
<_ForwardIterator
>::value_type
, _Tp
>)
987 __glibcxx_requires_partitioned_lower(__first
, __last
, __val
);
988 __glibcxx_requires_irreflexive2(__first
, __last
);
990 return std::__lower_bound(__first
, __last
, __val
,
991 __gnu_cxx::__ops::__iter_less_val());
994 /// This is a helper function for the sort routines and for random.tcc.
995 // Precondition: __n > 0.
996 inline _GLIBCXX_CONSTEXPR
int
998 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1000 inline _GLIBCXX_CONSTEXPR
unsigned
1002 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1004 inline _GLIBCXX_CONSTEXPR
long
1006 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1008 inline _GLIBCXX_CONSTEXPR
unsigned long
1009 __lg(unsigned long __n
)
1010 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1012 inline _GLIBCXX_CONSTEXPR
long long
1014 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1016 inline _GLIBCXX_CONSTEXPR
unsigned long long
1017 __lg(unsigned long long __n
)
1018 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1020 _GLIBCXX_END_NAMESPACE_VERSION
1022 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1025 * @brief Tests a range for element-wise equality.
1026 * @ingroup non_mutating_algorithms
1027 * @param __first1 An input iterator.
1028 * @param __last1 An input iterator.
1029 * @param __first2 An input iterator.
1030 * @return A boolean true or false.
1032 * This compares the elements of two ranges using @c == and returns true or
1033 * false depending on whether all of the corresponding elements of the
1036 template<typename _II1
, typename _II2
>
1038 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
1040 // concept requirements
1041 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1042 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1043 __glibcxx_function_requires(_EqualOpConcept
<
1044 typename iterator_traits
<_II1
>::value_type
,
1045 typename iterator_traits
<_II2
>::value_type
>)
1046 __glibcxx_requires_valid_range(__first1
, __last1
);
1048 return std::__equal_aux(std::__niter_base(__first1
),
1049 std::__niter_base(__last1
),
1050 std::__niter_base(__first2
));
1054 * @brief Tests a range for element-wise equality.
1055 * @ingroup non_mutating_algorithms
1056 * @param __first1 An input iterator.
1057 * @param __last1 An input iterator.
1058 * @param __first2 An input iterator.
1059 * @param __binary_pred A binary predicate @link functors
1061 * @return A boolean true or false.
1063 * This compares the elements of two ranges using the binary_pred
1064 * parameter, and returns true or
1065 * false depending on whether all of the corresponding elements of the
1068 template<typename _IIter1
, typename _IIter2
, typename _BinaryPredicate
>
1070 equal(_IIter1 __first1
, _IIter1 __last1
,
1071 _IIter2 __first2
, _BinaryPredicate __binary_pred
)
1073 // concept requirements
1074 __glibcxx_function_requires(_InputIteratorConcept
<_IIter1
>)
1075 __glibcxx_function_requires(_InputIteratorConcept
<_IIter2
>)
1076 __glibcxx_requires_valid_range(__first1
, __last1
);
1078 for (; __first1
!= __last1
; ++__first1
, (void)++__first2
)
1079 if (!bool(__binary_pred(*__first1
, *__first2
)))
1084 #if __cplusplus > 201103L
1086 #define __cpp_lib_robust_nonmodifying_seq_ops 201304
1089 * @brief Tests a range for element-wise equality.
1090 * @ingroup non_mutating_algorithms
1091 * @param __first1 An input iterator.
1092 * @param __last1 An input iterator.
1093 * @param __first2 An input iterator.
1094 * @param __last2 An input iterator.
1095 * @return A boolean true or false.
1097 * This compares the elements of two ranges using @c == and returns true or
1098 * false depending on whether all of the corresponding elements of the
1101 template<typename _II1
, typename _II2
>
1103 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
1105 // concept requirements
1106 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1107 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1108 __glibcxx_function_requires(_EqualOpConcept
<
1109 typename iterator_traits
<_II1
>::value_type
,
1110 typename iterator_traits
<_II2
>::value_type
>)
1111 __glibcxx_requires_valid_range(__first1
, __last1
);
1112 __glibcxx_requires_valid_range(__first2
, __last2
);
1114 using _RATag
= random_access_iterator_tag
;
1115 using _Cat1
= typename iterator_traits
<_II1
>::iterator_category
;
1116 using _Cat2
= typename iterator_traits
<_II2
>::iterator_category
;
1117 using _RAIters
= __and_
<is_same
<_Cat1
, _RATag
>, is_same
<_Cat2
, _RATag
>>;
1120 auto __d1
= std::distance(__first1
, __last1
);
1121 auto __d2
= std::distance(__first2
, __last2
);
1124 return _GLIBCXX_STD_A::equal(__first1
, __last1
, __first2
);
1127 for (; __first1
!= __last1
&& __first2
!= __last2
;
1128 ++__first1
, (void)++__first2
)
1129 if (!(*__first1
== *__first2
))
1131 return __first1
== __last1
&& __first2
== __last2
;
1135 * @brief Tests a range for element-wise equality.
1136 * @ingroup non_mutating_algorithms
1137 * @param __first1 An input iterator.
1138 * @param __last1 An input iterator.
1139 * @param __first2 An input iterator.
1140 * @param __last2 An input iterator.
1141 * @param __binary_pred A binary predicate @link functors
1143 * @return A boolean true or false.
1145 * This compares the elements of two ranges using the binary_pred
1146 * parameter, and returns true or
1147 * false depending on whether all of the corresponding elements of the
1150 template<typename _IIter1
, typename _IIter2
, typename _BinaryPredicate
>
1152 equal(_IIter1 __first1
, _IIter1 __last1
,
1153 _IIter2 __first2
, _IIter2 __last2
, _BinaryPredicate __binary_pred
)
1155 // concept requirements
1156 __glibcxx_function_requires(_InputIteratorConcept
<_IIter1
>)
1157 __glibcxx_function_requires(_InputIteratorConcept
<_IIter2
>)
1158 __glibcxx_requires_valid_range(__first1
, __last1
);
1159 __glibcxx_requires_valid_range(__first2
, __last2
);
1161 using _RATag
= random_access_iterator_tag
;
1162 using _Cat1
= typename iterator_traits
<_IIter1
>::iterator_category
;
1163 using _Cat2
= typename iterator_traits
<_IIter2
>::iterator_category
;
1164 using _RAIters
= __and_
<is_same
<_Cat1
, _RATag
>, is_same
<_Cat2
, _RATag
>>;
1167 auto __d1
= std::distance(__first1
, __last1
);
1168 auto __d2
= std::distance(__first2
, __last2
);
1171 return _GLIBCXX_STD_A::equal(__first1
, __last1
, __first2
,
1175 for (; __first1
!= __last1
&& __first2
!= __last2
;
1176 ++__first1
, (void)++__first2
)
1177 if (!bool(__binary_pred(*__first1
, *__first2
)))
1179 return __first1
== __last1
&& __first2
== __last2
;
1184 * @brief Performs @b dictionary comparison on ranges.
1185 * @ingroup sorting_algorithms
1186 * @param __first1 An input iterator.
1187 * @param __last1 An input iterator.
1188 * @param __first2 An input iterator.
1189 * @param __last2 An input iterator.
1190 * @return A boolean true or false.
1192 * <em>Returns true if the sequence of elements defined by the range
1193 * [first1,last1) is lexicographically less than the sequence of elements
1194 * defined by the range [first2,last2). Returns false otherwise.</em>
1195 * (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
1196 * then this is an inline call to @c memcmp.
1198 template<typename _II1
, typename _II2
>
1200 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1201 _II2 __first2
, _II2 __last2
)
1203 #ifdef _GLIBCXX_CONCEPT_CHECKS
1204 // concept requirements
1205 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
1206 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
1208 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1209 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1210 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType1
, _ValueType2
>)
1211 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType2
, _ValueType1
>)
1212 __glibcxx_requires_valid_range(__first1
, __last1
);
1213 __glibcxx_requires_irreflexive2(__first1
, __last1
);
1214 __glibcxx_requires_valid_range(__first2
, __last2
);
1215 __glibcxx_requires_irreflexive2(__first2
, __last2
);
1217 return std::__lexicographical_compare_aux(std::__niter_base(__first1
),
1218 std::__niter_base(__last1
),
1219 std::__niter_base(__first2
),
1220 std::__niter_base(__last2
));
1224 * @brief Performs @b dictionary comparison on ranges.
1225 * @ingroup sorting_algorithms
1226 * @param __first1 An input iterator.
1227 * @param __last1 An input iterator.
1228 * @param __first2 An input iterator.
1229 * @param __last2 An input iterator.
1230 * @param __comp A @link comparison_functors comparison functor@endlink.
1231 * @return A boolean true or false.
1233 * The same as the four-parameter @c lexicographical_compare, but uses the
1234 * comp parameter instead of @c <.
1236 template<typename _II1
, typename _II2
, typename _Compare
>
1238 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1239 _II2 __first2
, _II2 __last2
, _Compare __comp
)
1241 // concept requirements
1242 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1243 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1244 __glibcxx_requires_valid_range(__first1
, __last1
);
1245 __glibcxx_requires_irreflexive_pred2(__first1
, __last1
, __comp
);
1246 __glibcxx_requires_valid_range(__first2
, __last2
);
1247 __glibcxx_requires_irreflexive_pred2(__first2
, __last2
, __comp
);
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>