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 // Likewise for move_iterator.
281 template<typename _Iterator
>
283 __miter_base(_Iterator __it
)
286 // All of these auxiliary structs serve two purposes. (1) Replace
287 // calls to copy with memmove whenever possible. (Memmove, not memcpy,
288 // because the input and output ranges are permitted to overlap.)
289 // (2) If we're using random access iterators, then write the loop as
290 // a for loop with an explicit count.
292 template<bool, bool, typename
>
295 template<typename _II
, typename _OI
>
297 __copy_m(_II __first
, _II __last
, _OI __result
)
299 for (; __first
!= __last
; ++__result
, (void)++__first
)
300 *__result
= *__first
;
305 #if __cplusplus >= 201103L
306 template<typename _Category
>
307 struct __copy_move
<true, false, _Category
>
309 template<typename _II
, typename _OI
>
311 __copy_m(_II __first
, _II __last
, _OI __result
)
313 for (; __first
!= __last
; ++__result
, (void)++__first
)
314 *__result
= std::move(*__first
);
321 struct __copy_move
<false, false, random_access_iterator_tag
>
323 template<typename _II
, typename _OI
>
325 __copy_m(_II __first
, _II __last
, _OI __result
)
327 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
328 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
330 *__result
= *__first
;
338 #if __cplusplus >= 201103L
340 struct __copy_move
<true, false, random_access_iterator_tag
>
342 template<typename _II
, typename _OI
>
344 __copy_m(_II __first
, _II __last
, _OI __result
)
346 typedef typename iterator_traits
<_II
>::difference_type _Distance
;
347 for(_Distance __n
= __last
- __first
; __n
> 0; --__n
)
349 *__result
= std::move(*__first
);
358 template<bool _IsMove
>
359 struct __copy_move
<_IsMove
, true, random_access_iterator_tag
>
361 template<typename _Tp
>
363 __copy_m(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
365 #if __cplusplus >= 201103L
366 // trivial types can have deleted assignment
367 static_assert( is_copy_assignable
<_Tp
>::value
,
368 "type is not assignable" );
370 const ptrdiff_t _Num
= __last
- __first
;
372 __builtin_memmove(__result
, __first
, sizeof(_Tp
) * _Num
);
373 return __result
+ _Num
;
377 template<bool _IsMove
, typename _II
, typename _OI
>
379 __copy_move_a(_II __first
, _II __last
, _OI __result
)
381 typedef typename iterator_traits
<_II
>::value_type _ValueTypeI
;
382 typedef typename iterator_traits
<_OI
>::value_type _ValueTypeO
;
383 typedef typename iterator_traits
<_II
>::iterator_category _Category
;
384 const bool __simple
= (__is_trivial(_ValueTypeI
)
385 && __is_pointer
<_II
>::__value
386 && __is_pointer
<_OI
>::__value
387 && __are_same
<_ValueTypeI
, _ValueTypeO
>::__value
);
389 return std::__copy_move
<_IsMove
, __simple
,
390 _Category
>::__copy_m(__first
, __last
, __result
);
393 // Helpers for streambuf iterators (either istream or ostream).
394 // NB: avoid including <iosfwd>, relatively large.
395 template<typename _CharT
>
398 template<typename _CharT
, typename _Traits
>
399 class istreambuf_iterator
;
401 template<typename _CharT
, typename _Traits
>
402 class ostreambuf_iterator
;
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(_CharT
*, _CharT
*,
408 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
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(const _CharT
*, const _CharT
*,
414 ostreambuf_iterator
<_CharT
, char_traits
<_CharT
> >);
416 template<bool _IsMove
, typename _CharT
>
417 typename
__gnu_cxx::__enable_if
<__is_char
<_CharT
>::__value
,
419 __copy_move_a2(istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >,
420 istreambuf_iterator
<_CharT
, char_traits
<_CharT
> >, _CharT
*);
422 template<bool _IsMove
, typename _II
, typename _OI
>
424 __copy_move_a2(_II __first
, _II __last
, _OI __result
)
426 return _OI(std::__copy_move_a
<_IsMove
>(std::__niter_base(__first
),
427 std::__niter_base(__last
),
428 std::__niter_base(__result
)));
432 * @brief Copies the range [first,last) into result.
433 * @ingroup mutating_algorithms
434 * @param __first An input iterator.
435 * @param __last An input iterator.
436 * @param __result An output iterator.
437 * @return result + (first - last)
439 * This inline function will boil down to a call to @c memmove whenever
440 * possible. Failing that, if random access iterators are passed, then the
441 * loop count will be known (and therefore a candidate for compiler
442 * optimizations such as unrolling). Result may not be contained within
443 * [first,last); the copy_backward function should be used instead.
445 * Note that the end of the output range is permitted to be contained
446 * within [first,last).
448 template<typename _II
, typename _OI
>
450 copy(_II __first
, _II __last
, _OI __result
)
452 // concept requirements
453 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
454 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
455 typename iterator_traits
<_II
>::value_type
>)
456 __glibcxx_requires_valid_range(__first
, __last
);
458 return (std::__copy_move_a2
<__is_move_iterator
<_II
>::__value
>
459 (std::__miter_base(__first
), std::__miter_base(__last
),
463 #if __cplusplus >= 201103L
465 * @brief Moves the range [first,last) into result.
466 * @ingroup mutating_algorithms
467 * @param __first An input iterator.
468 * @param __last An input iterator.
469 * @param __result An output iterator.
470 * @return result + (first - last)
472 * This inline function will boil down to a call to @c memmove whenever
473 * possible. Failing that, if random access iterators are passed, then the
474 * loop count will be known (and therefore a candidate for compiler
475 * optimizations such as unrolling). Result may not be contained within
476 * [first,last); the move_backward function should be used instead.
478 * Note that the end of the output range is permitted to be contained
479 * within [first,last).
481 template<typename _II
, typename _OI
>
483 move(_II __first
, _II __last
, _OI __result
)
485 // concept requirements
486 __glibcxx_function_requires(_InputIteratorConcept
<_II
>)
487 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
,
488 typename iterator_traits
<_II
>::value_type
>)
489 __glibcxx_requires_valid_range(__first
, __last
);
491 return std::__copy_move_a2
<true>(std::__miter_base(__first
),
492 std::__miter_base(__last
), __result
);
495 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
497 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
500 template<bool, bool, typename
>
501 struct __copy_move_backward
503 template<typename _BI1
, typename _BI2
>
505 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
507 while (__first
!= __last
)
508 *--__result
= *--__last
;
513 #if __cplusplus >= 201103L
514 template<typename _Category
>
515 struct __copy_move_backward
<true, false, _Category
>
517 template<typename _BI1
, typename _BI2
>
519 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
521 while (__first
!= __last
)
522 *--__result
= std::move(*--__last
);
529 struct __copy_move_backward
<false, false, random_access_iterator_tag
>
531 template<typename _BI1
, typename _BI2
>
533 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
535 typename iterator_traits
<_BI1
>::difference_type __n
;
536 for (__n
= __last
- __first
; __n
> 0; --__n
)
537 *--__result
= *--__last
;
542 #if __cplusplus >= 201103L
544 struct __copy_move_backward
<true, false, random_access_iterator_tag
>
546 template<typename _BI1
, typename _BI2
>
548 __copy_move_b(_BI1 __first
, _BI1 __last
, _BI2 __result
)
550 typename iterator_traits
<_BI1
>::difference_type __n
;
551 for (__n
= __last
- __first
; __n
> 0; --__n
)
552 *--__result
= std::move(*--__last
);
558 template<bool _IsMove
>
559 struct __copy_move_backward
<_IsMove
, true, random_access_iterator_tag
>
561 template<typename _Tp
>
563 __copy_move_b(const _Tp
* __first
, const _Tp
* __last
, _Tp
* __result
)
565 #if __cplusplus >= 201103L
566 // trivial types can have deleted assignment
567 static_assert( is_copy_assignable
<_Tp
>::value
,
568 "type is not assignable" );
570 const ptrdiff_t _Num
= __last
- __first
;
572 __builtin_memmove(__result
- _Num
, __first
, sizeof(_Tp
) * _Num
);
573 return __result
- _Num
;
577 template<bool _IsMove
, typename _BI1
, typename _BI2
>
579 __copy_move_backward_a(_BI1 __first
, _BI1 __last
, _BI2 __result
)
581 typedef typename iterator_traits
<_BI1
>::value_type _ValueType1
;
582 typedef typename iterator_traits
<_BI2
>::value_type _ValueType2
;
583 typedef typename iterator_traits
<_BI1
>::iterator_category _Category
;
584 const bool __simple
= (__is_trivial(_ValueType1
)
585 && __is_pointer
<_BI1
>::__value
586 && __is_pointer
<_BI2
>::__value
587 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
589 return std::__copy_move_backward
<_IsMove
, __simple
,
590 _Category
>::__copy_move_b(__first
,
595 template<bool _IsMove
, typename _BI1
, typename _BI2
>
597 __copy_move_backward_a2(_BI1 __first
, _BI1 __last
, _BI2 __result
)
599 return _BI2(std::__copy_move_backward_a
<_IsMove
>
600 (std::__niter_base(__first
), std::__niter_base(__last
),
601 std::__niter_base(__result
)));
605 * @brief Copies the range [first,last) into result.
606 * @ingroup mutating_algorithms
607 * @param __first A bidirectional iterator.
608 * @param __last A bidirectional iterator.
609 * @param __result A bidirectional iterator.
610 * @return result - (first - last)
612 * The function has the same effect as copy, but starts at the end of the
613 * range and works its way to the start, returning the start of the result.
614 * This inline function will boil down to a call to @c memmove whenever
615 * possible. Failing that, if random access iterators are passed, then the
616 * loop count will be known (and therefore a candidate for compiler
617 * optimizations such as unrolling).
619 * Result may not be in the range (first,last]. Use copy instead. Note
620 * that the start of the output range may overlap [first,last).
622 template<typename _BI1
, typename _BI2
>
624 copy_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
626 // concept requirements
627 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
628 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
629 __glibcxx_function_requires(_ConvertibleConcept
<
630 typename iterator_traits
<_BI1
>::value_type
,
631 typename iterator_traits
<_BI2
>::value_type
>)
632 __glibcxx_requires_valid_range(__first
, __last
);
634 return (std::__copy_move_backward_a2
<__is_move_iterator
<_BI1
>::__value
>
635 (std::__miter_base(__first
), std::__miter_base(__last
),
639 #if __cplusplus >= 201103L
641 * @brief Moves the range [first,last) into result.
642 * @ingroup mutating_algorithms
643 * @param __first A bidirectional iterator.
644 * @param __last A bidirectional iterator.
645 * @param __result A bidirectional iterator.
646 * @return result - (first - last)
648 * The function has the same effect as move, but starts at the end of the
649 * range and works its way to the start, returning the start of the result.
650 * This inline function will boil down to a call to @c memmove whenever
651 * possible. Failing that, if random access iterators are passed, then the
652 * loop count will be known (and therefore a candidate for compiler
653 * optimizations such as unrolling).
655 * Result may not be in the range (first,last]. Use move instead. Note
656 * that the start of the output range may overlap [first,last).
658 template<typename _BI1
, typename _BI2
>
660 move_backward(_BI1 __first
, _BI1 __last
, _BI2 __result
)
662 // concept requirements
663 __glibcxx_function_requires(_BidirectionalIteratorConcept
<_BI1
>)
664 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept
<_BI2
>)
665 __glibcxx_function_requires(_ConvertibleConcept
<
666 typename iterator_traits
<_BI1
>::value_type
,
667 typename iterator_traits
<_BI2
>::value_type
>)
668 __glibcxx_requires_valid_range(__first
, __last
);
670 return std::__copy_move_backward_a2
<true>(std::__miter_base(__first
),
671 std::__miter_base(__last
),
675 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
677 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
680 template<typename _ForwardIterator
, typename _Tp
>
682 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, void>::__type
683 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
686 for (; __first
!= __last
; ++__first
)
690 template<typename _ForwardIterator
, typename _Tp
>
692 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, void>::__type
693 __fill_a(_ForwardIterator __first
, _ForwardIterator __last
,
696 const _Tp __tmp
= __value
;
697 for (; __first
!= __last
; ++__first
)
701 // Specialization: for char types we can use memset.
702 template<typename _Tp
>
704 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, void>::__type
705 __fill_a(_Tp
* __first
, _Tp
* __last
, const _Tp
& __c
)
707 const _Tp __tmp
= __c
;
708 if (const size_t __len
= __last
- __first
)
709 __builtin_memset(__first
, static_cast<unsigned char>(__tmp
), __len
);
713 * @brief Fills the range [first,last) with copies of value.
714 * @ingroup mutating_algorithms
715 * @param __first A forward iterator.
716 * @param __last A forward iterator.
717 * @param __value A reference-to-const of arbitrary type.
720 * This function fills a range with copies of the same value. For char
721 * types filling contiguous areas of memory, this becomes an inline call
722 * to @c memset or @c wmemset.
724 template<typename _ForwardIterator
, typename _Tp
>
726 fill(_ForwardIterator __first
, _ForwardIterator __last
, const _Tp
& __value
)
728 // concept requirements
729 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept
<
731 __glibcxx_requires_valid_range(__first
, __last
);
733 std::__fill_a(std::__niter_base(__first
), std::__niter_base(__last
),
737 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
739 __gnu_cxx::__enable_if
<!__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
740 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
742 for (__decltype(__n
+ 0) __niter
= __n
;
743 __niter
> 0; --__niter
, ++__first
)
748 template<typename _OutputIterator
, typename _Size
, typename _Tp
>
750 __gnu_cxx::__enable_if
<__is_scalar
<_Tp
>::__value
, _OutputIterator
>::__type
751 __fill_n_a(_OutputIterator __first
, _Size __n
, const _Tp
& __value
)
753 const _Tp __tmp
= __value
;
754 for (__decltype(__n
+ 0) __niter
= __n
;
755 __niter
> 0; --__niter
, ++__first
)
760 template<typename _Size
, typename _Tp
>
762 __gnu_cxx::__enable_if
<__is_byte
<_Tp
>::__value
, _Tp
*>::__type
763 __fill_n_a(_Tp
* __first
, _Size __n
, const _Tp
& __c
)
765 std::__fill_a(__first
, __first
+ __n
, __c
);
766 return __first
+ __n
;
770 * @brief Fills the range [first,first+n) with copies of value.
771 * @ingroup mutating_algorithms
772 * @param __first An output iterator.
773 * @param __n The count of copies to perform.
774 * @param __value A reference-to-const of arbitrary type.
775 * @return The iterator at first+n.
777 * This function fills a range with copies of the same value. For char
778 * types filling contiguous areas of memory, this becomes an inline call
779 * to @c memset or @ wmemset.
781 * _GLIBCXX_RESOLVE_LIB_DEFECTS
782 * DR 865. More algorithms that throw away information
784 template<typename _OI
, typename _Size
, typename _Tp
>
786 fill_n(_OI __first
, _Size __n
, const _Tp
& __value
)
788 // concept requirements
789 __glibcxx_function_requires(_OutputIteratorConcept
<_OI
, _Tp
>)
791 return _OI(std::__fill_n_a(std::__niter_base(__first
), __n
, __value
));
794 template<bool _BoolType
>
797 template<typename _II1
, typename _II2
>
799 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
801 for (; __first1
!= __last1
; ++__first1
, (void)++__first2
)
802 if (!(*__first1
== *__first2
))
811 template<typename _Tp
>
813 equal(const _Tp
* __first1
, const _Tp
* __last1
, const _Tp
* __first2
)
815 if (const size_t __len
= (__last1
- __first1
))
816 return !__builtin_memcmp(__first1
, __first2
, sizeof(_Tp
) * __len
);
821 template<typename _II1
, typename _II2
>
823 __equal_aux(_II1 __first1
, _II1 __last1
, _II2 __first2
)
825 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
826 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
827 const bool __simple
= ((__is_integer
<_ValueType1
>::__value
828 || __is_pointer
<_ValueType1
>::__value
)
829 && __is_pointer
<_II1
>::__value
830 && __is_pointer
<_II2
>::__value
831 && __are_same
<_ValueType1
, _ValueType2
>::__value
);
833 return std::__equal
<__simple
>::equal(__first1
, __last1
, __first2
);
836 template<typename
, typename
>
839 template<typename _II1
, typename _II2
>
841 __newlast1(_II1
, _II1 __last1
, _II2
, _II2
)
844 template<typename _II
>
846 __cnd2(_II __first
, _II __last
)
847 { return __first
!= __last
; }
851 struct __lc_rai
<random_access_iterator_tag
, random_access_iterator_tag
>
853 template<typename _RAI1
, typename _RAI2
>
855 __newlast1(_RAI1 __first1
, _RAI1 __last1
,
856 _RAI2 __first2
, _RAI2 __last2
)
858 const typename iterator_traits
<_RAI1
>::difference_type
859 __diff1
= __last1
- __first1
;
860 const typename iterator_traits
<_RAI2
>::difference_type
861 __diff2
= __last2
- __first2
;
862 return __diff2
< __diff1
? __first1
+ __diff2
: __last1
;
865 template<typename _RAI
>
871 template<typename _II1
, typename _II2
, typename _Compare
>
873 __lexicographical_compare_impl(_II1 __first1
, _II1 __last1
,
874 _II2 __first2
, _II2 __last2
,
877 typedef typename iterator_traits
<_II1
>::iterator_category _Category1
;
878 typedef typename iterator_traits
<_II2
>::iterator_category _Category2
;
879 typedef std::__lc_rai
<_Category1
, _Category2
> __rai_type
;
881 __last1
= __rai_type::__newlast1(__first1
, __last1
, __first2
, __last2
);
882 for (; __first1
!= __last1
&& __rai_type::__cnd2(__first2
, __last2
);
883 ++__first1
, (void)++__first2
)
885 if (__comp(__first1
, __first2
))
887 if (__comp(__first2
, __first1
))
890 return __first1
== __last1
&& __first2
!= __last2
;
893 template<bool _BoolType
>
894 struct __lexicographical_compare
896 template<typename _II1
, typename _II2
>
897 static bool __lc(_II1
, _II1
, _II2
, _II2
);
900 template<bool _BoolType
>
901 template<typename _II1
, typename _II2
>
903 __lexicographical_compare
<_BoolType
>::
904 __lc(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
906 return std::__lexicographical_compare_impl(__first1
, __last1
,
908 __gnu_cxx::__ops::__iter_less_iter());
912 struct __lexicographical_compare
<true>
914 template<typename _Tp
, typename _Up
>
916 __lc(const _Tp
* __first1
, const _Tp
* __last1
,
917 const _Up
* __first2
, const _Up
* __last2
)
919 const size_t __len1
= __last1
- __first1
;
920 const size_t __len2
= __last2
- __first2
;
921 if (const size_t __len
= std::min(__len1
, __len2
))
922 if (int __result
= __builtin_memcmp(__first1
, __first2
, __len
))
924 return __len1
< __len2
;
928 template<typename _II1
, typename _II2
>
930 __lexicographical_compare_aux(_II1 __first1
, _II1 __last1
,
931 _II2 __first2
, _II2 __last2
)
933 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
934 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
935 const bool __simple
=
936 (__is_byte
<_ValueType1
>::__value
&& __is_byte
<_ValueType2
>::__value
937 && !__gnu_cxx::__numeric_traits
<_ValueType1
>::__is_signed
938 && !__gnu_cxx::__numeric_traits
<_ValueType2
>::__is_signed
939 && __is_pointer
<_II1
>::__value
940 && __is_pointer
<_II2
>::__value
);
942 return std::__lexicographical_compare
<__simple
>::__lc(__first1
, __last1
,
946 template<typename _ForwardIterator
, typename _Tp
, typename _Compare
>
948 __lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
949 const _Tp
& __val
, _Compare __comp
)
951 typedef typename iterator_traits
<_ForwardIterator
>::difference_type
954 _DistanceType __len
= std::distance(__first
, __last
);
958 _DistanceType __half
= __len
>> 1;
959 _ForwardIterator __middle
= __first
;
960 std::advance(__middle
, __half
);
961 if (__comp(__middle
, __val
))
965 __len
= __len
- __half
- 1;
974 * @brief Finds the first position in which @a val could be inserted
975 * without changing the ordering.
976 * @param __first An iterator.
977 * @param __last Another iterator.
978 * @param __val The search term.
979 * @return An iterator pointing to the first element <em>not less
980 * than</em> @a val, or end() if every element is less than
982 * @ingroup binary_search_algorithms
984 template<typename _ForwardIterator
, typename _Tp
>
985 inline _ForwardIterator
986 lower_bound(_ForwardIterator __first
, _ForwardIterator __last
,
989 // concept requirements
990 __glibcxx_function_requires(_ForwardIteratorConcept
<_ForwardIterator
>)
991 __glibcxx_function_requires(_LessThanOpConcept
<
992 typename iterator_traits
<_ForwardIterator
>::value_type
, _Tp
>)
993 __glibcxx_requires_partitioned_lower(__first
, __last
, __val
);
995 return std::__lower_bound(__first
, __last
, __val
,
996 __gnu_cxx::__ops::__iter_less_val());
999 /// This is a helper function for the sort routines and for random.tcc.
1000 // Precondition: __n > 0.
1001 inline _GLIBCXX_CONSTEXPR
int
1003 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1005 inline _GLIBCXX_CONSTEXPR
unsigned
1007 { return sizeof(int) * __CHAR_BIT__
- 1 - __builtin_clz(__n
); }
1009 inline _GLIBCXX_CONSTEXPR
long
1011 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1013 inline _GLIBCXX_CONSTEXPR
unsigned long
1014 __lg(unsigned long __n
)
1015 { return sizeof(long) * __CHAR_BIT__
- 1 - __builtin_clzl(__n
); }
1017 inline _GLIBCXX_CONSTEXPR
long long
1019 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1021 inline _GLIBCXX_CONSTEXPR
unsigned long long
1022 __lg(unsigned long long __n
)
1023 { return sizeof(long long) * __CHAR_BIT__
- 1 - __builtin_clzll(__n
); }
1025 _GLIBCXX_END_NAMESPACE_VERSION
1027 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1030 * @brief Tests a range for element-wise equality.
1031 * @ingroup non_mutating_algorithms
1032 * @param __first1 An input iterator.
1033 * @param __last1 An input iterator.
1034 * @param __first2 An input iterator.
1035 * @return A boolean true or false.
1037 * This compares the elements of two ranges using @c == and returns true or
1038 * false depending on whether all of the corresponding elements of the
1041 template<typename _II1
, typename _II2
>
1043 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
)
1045 // concept requirements
1046 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1047 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1048 __glibcxx_function_requires(_EqualOpConcept
<
1049 typename iterator_traits
<_II1
>::value_type
,
1050 typename iterator_traits
<_II2
>::value_type
>)
1051 __glibcxx_requires_valid_range(__first1
, __last1
);
1053 return std::__equal_aux(std::__niter_base(__first1
),
1054 std::__niter_base(__last1
),
1055 std::__niter_base(__first2
));
1059 * @brief Tests a range for element-wise equality.
1060 * @ingroup non_mutating_algorithms
1061 * @param __first1 An input iterator.
1062 * @param __last1 An input iterator.
1063 * @param __first2 An input iterator.
1064 * @param __binary_pred A binary predicate @link functors
1066 * @return A boolean true or false.
1068 * This compares the elements of two ranges using the binary_pred
1069 * parameter, and returns true or
1070 * false depending on whether all of the corresponding elements of the
1073 template<typename _IIter1
, typename _IIter2
, typename _BinaryPredicate
>
1075 equal(_IIter1 __first1
, _IIter1 __last1
,
1076 _IIter2 __first2
, _BinaryPredicate __binary_pred
)
1078 // concept requirements
1079 __glibcxx_function_requires(_InputIteratorConcept
<_IIter1
>)
1080 __glibcxx_function_requires(_InputIteratorConcept
<_IIter2
>)
1081 __glibcxx_requires_valid_range(__first1
, __last1
);
1083 for (; __first1
!= __last1
; ++__first1
, (void)++__first2
)
1084 if (!bool(__binary_pred(*__first1
, *__first2
)))
1089 #if __cplusplus > 201103L
1091 #define __cpp_lib_robust_nonmodifying_seq_ops 201304
1094 * @brief Tests a range for element-wise equality.
1095 * @ingroup non_mutating_algorithms
1096 * @param __first1 An input iterator.
1097 * @param __last1 An input iterator.
1098 * @param __first2 An input iterator.
1099 * @param __last2 An input iterator.
1100 * @return A boolean true or false.
1102 * This compares the elements of two ranges using @c == and returns true or
1103 * false depending on whether all of the corresponding elements of the
1106 template<typename _II1
, typename _II2
>
1108 equal(_II1 __first1
, _II1 __last1
, _II2 __first2
, _II2 __last2
)
1110 // concept requirements
1111 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1112 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1113 __glibcxx_function_requires(_EqualOpConcept
<
1114 typename iterator_traits
<_II1
>::value_type
,
1115 typename iterator_traits
<_II2
>::value_type
>)
1116 __glibcxx_requires_valid_range(__first1
, __last1
);
1117 __glibcxx_requires_valid_range(__first2
, __last2
);
1119 using _RATag
= random_access_iterator_tag
;
1120 using _Cat1
= typename iterator_traits
<_II1
>::iterator_category
;
1121 using _Cat2
= typename iterator_traits
<_II2
>::iterator_category
;
1122 using _RAIters
= __and_
<is_same
<_Cat1
, _RATag
>, is_same
<_Cat2
, _RATag
>>;
1125 auto __d1
= std::distance(__first1
, __last1
);
1126 auto __d2
= std::distance(__first2
, __last2
);
1129 return _GLIBCXX_STD_A::equal(__first1
, __last1
, __first2
);
1132 for (; __first1
!= __last1
&& __first2
!= __last2
;
1133 ++__first1
, (void)++__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
;
1181 ++__first1
, (void)++__first2
)
1182 if (!bool(__binary_pred(*__first1
, *__first2
)))
1184 return __first1
== __last1
&& __first2
== __last2
;
1189 * @brief Performs @b dictionary comparison on ranges.
1190 * @ingroup sorting_algorithms
1191 * @param __first1 An input iterator.
1192 * @param __last1 An input iterator.
1193 * @param __first2 An input iterator.
1194 * @param __last2 An input iterator.
1195 * @return A boolean true or false.
1197 * <em>Returns true if the sequence of elements defined by the range
1198 * [first1,last1) is lexicographically less than the sequence of elements
1199 * defined by the range [first2,last2). Returns false otherwise.</em>
1200 * (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
1201 * then this is an inline call to @c memcmp.
1203 template<typename _II1
, typename _II2
>
1205 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1206 _II2 __first2
, _II2 __last2
)
1208 #ifdef _GLIBCXX_CONCEPT_CHECKS
1209 // concept requirements
1210 typedef typename iterator_traits
<_II1
>::value_type _ValueType1
;
1211 typedef typename iterator_traits
<_II2
>::value_type _ValueType2
;
1213 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1214 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1215 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType1
, _ValueType2
>)
1216 __glibcxx_function_requires(_LessThanOpConcept
<_ValueType2
, _ValueType1
>)
1217 __glibcxx_requires_valid_range(__first1
, __last1
);
1218 __glibcxx_requires_valid_range(__first2
, __last2
);
1220 return std::__lexicographical_compare_aux(std::__niter_base(__first1
),
1221 std::__niter_base(__last1
),
1222 std::__niter_base(__first2
),
1223 std::__niter_base(__last2
));
1227 * @brief Performs @b dictionary comparison on ranges.
1228 * @ingroup sorting_algorithms
1229 * @param __first1 An input iterator.
1230 * @param __last1 An input iterator.
1231 * @param __first2 An input iterator.
1232 * @param __last2 An input iterator.
1233 * @param __comp A @link comparison_functors comparison functor@endlink.
1234 * @return A boolean true or false.
1236 * The same as the four-parameter @c lexicographical_compare, but uses the
1237 * comp parameter instead of @c <.
1239 template<typename _II1
, typename _II2
, typename _Compare
>
1241 lexicographical_compare(_II1 __first1
, _II1 __last1
,
1242 _II2 __first2
, _II2 __last2
, _Compare __comp
)
1244 // concept requirements
1245 __glibcxx_function_requires(_InputIteratorConcept
<_II1
>)
1246 __glibcxx_function_requires(_InputIteratorConcept
<_II2
>)
1247 __glibcxx_requires_valid_range(__first1
, __last1
);
1248 __glibcxx_requires_valid_range(__first2
, __last2
);
1250 return std::__lexicographical_compare_impl
1251 (__first1
, __last1
, __first2
, __last2
,
1252 __gnu_cxx::__ops::__iter_comp_iter(__comp
));
1255 template<typename _InputIterator1
, typename _InputIterator2
,
1256 typename _BinaryPredicate
>
1257 pair
<_InputIterator1
, _InputIterator2
>
1258 __mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1259 _InputIterator2 __first2
, _BinaryPredicate __binary_pred
)
1261 while (__first1
!= __last1
&& __binary_pred(__first1
, __first2
))
1266 return pair
<_InputIterator1
, _InputIterator2
>(__first1
, __first2
);
1270 * @brief Finds the places in ranges which don't match.
1271 * @ingroup non_mutating_algorithms
1272 * @param __first1 An input iterator.
1273 * @param __last1 An input iterator.
1274 * @param __first2 An input iterator.
1275 * @return A pair of iterators pointing to the first mismatch.
1277 * This compares the elements of two ranges using @c == and returns a pair
1278 * of iterators. The first iterator points into the first range, the
1279 * second iterator points into the second range, and the elements pointed
1280 * to by the iterators are not equal.
1282 template<typename _InputIterator1
, typename _InputIterator2
>
1283 inline pair
<_InputIterator1
, _InputIterator2
>
1284 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1285 _InputIterator2 __first2
)
1287 // concept requirements
1288 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1289 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1290 __glibcxx_function_requires(_EqualOpConcept
<
1291 typename iterator_traits
<_InputIterator1
>::value_type
,
1292 typename iterator_traits
<_InputIterator2
>::value_type
>)
1293 __glibcxx_requires_valid_range(__first1
, __last1
);
1295 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
,
1296 __gnu_cxx::__ops::__iter_equal_to_iter());
1300 * @brief Finds the places in ranges which don't match.
1301 * @ingroup non_mutating_algorithms
1302 * @param __first1 An input iterator.
1303 * @param __last1 An input iterator.
1304 * @param __first2 An input iterator.
1305 * @param __binary_pred A binary predicate @link functors
1307 * @return A pair of iterators pointing to the first mismatch.
1309 * This compares the elements of two ranges using the binary_pred
1310 * parameter, and returns a pair
1311 * of iterators. The first iterator points into the first range, the
1312 * second iterator points into the second range, and the elements pointed
1313 * to by the iterators are not equal.
1315 template<typename _InputIterator1
, typename _InputIterator2
,
1316 typename _BinaryPredicate
>
1317 inline pair
<_InputIterator1
, _InputIterator2
>
1318 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1319 _InputIterator2 __first2
, _BinaryPredicate __binary_pred
)
1321 // concept requirements
1322 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1323 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1324 __glibcxx_requires_valid_range(__first1
, __last1
);
1326 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
,
1327 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred
));
1330 #if __cplusplus > 201103L
1332 template<typename _InputIterator1
, typename _InputIterator2
,
1333 typename _BinaryPredicate
>
1334 pair
<_InputIterator1
, _InputIterator2
>
1335 __mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1336 _InputIterator2 __first2
, _InputIterator2 __last2
,
1337 _BinaryPredicate __binary_pred
)
1339 while (__first1
!= __last1
&& __first2
!= __last2
1340 && __binary_pred(__first1
, __first2
))
1345 return pair
<_InputIterator1
, _InputIterator2
>(__first1
, __first2
);
1349 * @brief Finds the places in ranges which don't match.
1350 * @ingroup non_mutating_algorithms
1351 * @param __first1 An input iterator.
1352 * @param __last1 An input iterator.
1353 * @param __first2 An input iterator.
1354 * @param __last2 An input iterator.
1355 * @return A pair of iterators pointing to the first mismatch.
1357 * This compares the elements of two ranges using @c == and returns a pair
1358 * of iterators. The first iterator points into the first range, the
1359 * second iterator points into the second range, and the elements pointed
1360 * to by the iterators are not equal.
1362 template<typename _InputIterator1
, typename _InputIterator2
>
1363 inline pair
<_InputIterator1
, _InputIterator2
>
1364 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1365 _InputIterator2 __first2
, _InputIterator2 __last2
)
1367 // concept requirements
1368 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1369 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1370 __glibcxx_function_requires(_EqualOpConcept
<
1371 typename iterator_traits
<_InputIterator1
>::value_type
,
1372 typename iterator_traits
<_InputIterator2
>::value_type
>)
1373 __glibcxx_requires_valid_range(__first1
, __last1
);
1374 __glibcxx_requires_valid_range(__first2
, __last2
);
1376 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
, __last2
,
1377 __gnu_cxx::__ops::__iter_equal_to_iter());
1381 * @brief Finds the places in ranges which don't match.
1382 * @ingroup non_mutating_algorithms
1383 * @param __first1 An input iterator.
1384 * @param __last1 An input iterator.
1385 * @param __first2 An input iterator.
1386 * @param __last2 An input iterator.
1387 * @param __binary_pred A binary predicate @link functors
1389 * @return A pair of iterators pointing to the first mismatch.
1391 * This compares the elements of two ranges using the binary_pred
1392 * parameter, and returns a pair
1393 * of iterators. The first iterator points into the first range, the
1394 * second iterator points into the second range, and the elements pointed
1395 * to by the iterators are not equal.
1397 template<typename _InputIterator1
, typename _InputIterator2
,
1398 typename _BinaryPredicate
>
1399 inline pair
<_InputIterator1
, _InputIterator2
>
1400 mismatch(_InputIterator1 __first1
, _InputIterator1 __last1
,
1401 _InputIterator2 __first2
, _InputIterator2 __last2
,
1402 _BinaryPredicate __binary_pred
)
1404 // concept requirements
1405 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator1
>)
1406 __glibcxx_function_requires(_InputIteratorConcept
<_InputIterator2
>)
1407 __glibcxx_requires_valid_range(__first1
, __last1
);
1408 __glibcxx_requires_valid_range(__first2
, __last2
);
1410 return _GLIBCXX_STD_A::__mismatch(__first1
, __last1
, __first2
, __last2
,
1411 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred
));
1415 _GLIBCXX_END_NAMESPACE_ALGO
1418 // NB: This file is included within many other C++ includes, as a way
1419 // of getting the base algorithms. So, make sure that parallel bits
1420 // come in too if requested.
1421 #ifdef _GLIBCXX_PARALLEL
1422 # include <parallel/algobase.h>