]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_algobase.h
libstdc++: Make __gnu_debug::vector usable in constant expressions [PR109536]
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_algobase.h
1 // Core algorithmic facilities -*- C++ -*-
2
3 // Copyright (C) 2001-2023 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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.
19
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/>.
24
25 /*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
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.
37 *
38 *
39 * Copyright (c) 1996-1998
40 * Silicon Graphics Computer Systems, Inc.
41 *
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.
49 */
50
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}
54 */
55
56 #ifndef _STL_ALGOBASE_H
57 #define _STL_ALGOBASE_H 1
58
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
71 #include <bits/predefined_ops.h>
72 #if __cplusplus >= 201103L
73 # include <type_traits>
74 #endif
75 #if __cplusplus >= 201402L
76 # include <bit> // std::__bit_width
77 #endif
78 #if __cplusplus >= 202002L
79 # include <compare>
80 #endif
81
82 namespace std _GLIBCXX_VISIBILITY(default)
83 {
84 _GLIBCXX_BEGIN_NAMESPACE_VERSION
85
86 /*
87 * A constexpr wrapper for __builtin_memcmp.
88 * @param __num The number of elements of type _Tp (not bytes).
89 */
90 template<typename _Tp, typename _Up>
91 _GLIBCXX14_CONSTEXPR
92 inline int
93 __memcmp(const _Tp* __first1, const _Up* __first2, size_t __num)
94 {
95 #if __cplusplus >= 201103L
96 static_assert(sizeof(_Tp) == sizeof(_Up), "can be compared with memcmp");
97 #endif
98 #ifdef __cpp_lib_is_constant_evaluated
99 if (std::is_constant_evaluated())
100 {
101 for(; __num > 0; ++__first1, ++__first2, --__num)
102 if (*__first1 != *__first2)
103 return *__first1 < *__first2 ? -1 : 1;
104 return 0;
105 }
106 else
107 #endif
108 return __builtin_memcmp(__first1, __first2, sizeof(_Tp) * __num);
109 }
110
111 #if __cplusplus < 201103L
112 // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
113 // nutshell, we are partially implementing the resolution of DR 187,
114 // when it's safe, i.e., the value_types are equal.
115 template<bool _BoolType>
116 struct __iter_swap
117 {
118 template<typename _ForwardIterator1, typename _ForwardIterator2>
119 static void
120 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
121 {
122 typedef typename iterator_traits<_ForwardIterator1>::value_type
123 _ValueType1;
124 _ValueType1 __tmp = *__a;
125 *__a = *__b;
126 *__b = __tmp;
127 }
128 };
129
130 template<>
131 struct __iter_swap<true>
132 {
133 template<typename _ForwardIterator1, typename _ForwardIterator2>
134 static void
135 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
136 {
137 swap(*__a, *__b);
138 }
139 };
140 #endif // C++03
141
142 /**
143 * @brief Swaps the contents of two iterators.
144 * @ingroup mutating_algorithms
145 * @param __a An iterator.
146 * @param __b Another iterator.
147 * @return Nothing.
148 *
149 * This function swaps the values pointed to by two iterators, not the
150 * iterators themselves.
151 */
152 template<typename _ForwardIterator1, typename _ForwardIterator2>
153 _GLIBCXX20_CONSTEXPR
154 inline void
155 iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
156 {
157 // concept requirements
158 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
159 _ForwardIterator1>)
160 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
161 _ForwardIterator2>)
162
163 #if __cplusplus < 201103L
164 typedef typename iterator_traits<_ForwardIterator1>::value_type
165 _ValueType1;
166 typedef typename iterator_traits<_ForwardIterator2>::value_type
167 _ValueType2;
168
169 __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
170 _ValueType2>)
171 __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
172 _ValueType1>)
173
174 typedef typename iterator_traits<_ForwardIterator1>::reference
175 _ReferenceType1;
176 typedef typename iterator_traits<_ForwardIterator2>::reference
177 _ReferenceType2;
178 std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
179 && __are_same<_ValueType1&, _ReferenceType1>::__value
180 && __are_same<_ValueType2&, _ReferenceType2>::__value>::
181 iter_swap(__a, __b);
182 #else
183 // _GLIBCXX_RESOLVE_LIB_DEFECTS
184 // 187. iter_swap underspecified
185 swap(*__a, *__b);
186 #endif
187 }
188
189 /**
190 * @brief Swap the elements of two sequences.
191 * @ingroup mutating_algorithms
192 * @param __first1 A forward iterator.
193 * @param __last1 A forward iterator.
194 * @param __first2 A forward iterator.
195 * @return An iterator equal to @p first2+(last1-first1).
196 *
197 * Swaps each element in the range @p [first1,last1) with the
198 * corresponding element in the range @p [first2,(last1-first1)).
199 * The ranges must not overlap.
200 */
201 template<typename _ForwardIterator1, typename _ForwardIterator2>
202 _GLIBCXX20_CONSTEXPR
203 _ForwardIterator2
204 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
205 _ForwardIterator2 __first2)
206 {
207 // concept requirements
208 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
209 _ForwardIterator1>)
210 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
211 _ForwardIterator2>)
212 __glibcxx_requires_valid_range(__first1, __last1);
213
214 for (; __first1 != __last1; ++__first1, (void)++__first2)
215 std::iter_swap(__first1, __first2);
216 return __first2;
217 }
218
219 /**
220 * @brief This does what you think it does.
221 * @ingroup sorting_algorithms
222 * @param __a A thing of arbitrary type.
223 * @param __b Another thing of arbitrary type.
224 * @return The lesser of the parameters.
225 *
226 * This is the simple classic generic implementation. It will work on
227 * temporary expressions, since they are only evaluated once, unlike a
228 * preprocessor macro.
229 */
230 template<typename _Tp>
231 _GLIBCXX14_CONSTEXPR
232 inline const _Tp&
233 min(const _Tp& __a, const _Tp& __b)
234 {
235 // concept requirements
236 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
237 //return __b < __a ? __b : __a;
238 if (__b < __a)
239 return __b;
240 return __a;
241 }
242
243 /**
244 * @brief This does what you think it does.
245 * @ingroup sorting_algorithms
246 * @param __a A thing of arbitrary type.
247 * @param __b Another thing of arbitrary type.
248 * @return The greater of the parameters.
249 *
250 * This is the simple classic generic implementation. It will work on
251 * temporary expressions, since they are only evaluated once, unlike a
252 * preprocessor macro.
253 */
254 template<typename _Tp>
255 _GLIBCXX14_CONSTEXPR
256 inline const _Tp&
257 max(const _Tp& __a, const _Tp& __b)
258 {
259 // concept requirements
260 __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
261 //return __a < __b ? __b : __a;
262 if (__a < __b)
263 return __b;
264 return __a;
265 }
266
267 /**
268 * @brief This does what you think it does.
269 * @ingroup sorting_algorithms
270 * @param __a A thing of arbitrary type.
271 * @param __b Another thing of arbitrary type.
272 * @param __comp A @link comparison_functors comparison functor@endlink.
273 * @return The lesser of the parameters.
274 *
275 * This will work on temporary expressions, since they are only evaluated
276 * once, unlike a preprocessor macro.
277 */
278 template<typename _Tp, typename _Compare>
279 _GLIBCXX14_CONSTEXPR
280 inline const _Tp&
281 min(const _Tp& __a, const _Tp& __b, _Compare __comp)
282 {
283 //return __comp(__b, __a) ? __b : __a;
284 if (__comp(__b, __a))
285 return __b;
286 return __a;
287 }
288
289 /**
290 * @brief This does what you think it does.
291 * @ingroup sorting_algorithms
292 * @param __a A thing of arbitrary type.
293 * @param __b Another thing of arbitrary type.
294 * @param __comp A @link comparison_functors comparison functor@endlink.
295 * @return The greater of the parameters.
296 *
297 * This will work on temporary expressions, since they are only evaluated
298 * once, unlike a preprocessor macro.
299 */
300 template<typename _Tp, typename _Compare>
301 _GLIBCXX14_CONSTEXPR
302 inline const _Tp&
303 max(const _Tp& __a, const _Tp& __b, _Compare __comp)
304 {
305 //return __comp(__a, __b) ? __b : __a;
306 if (__comp(__a, __b))
307 return __b;
308 return __a;
309 }
310
311 // Fallback implementation of the function in bits/stl_iterator.h used to
312 // remove the __normal_iterator wrapper. See copy, fill, ...
313 template<typename _Iterator>
314 _GLIBCXX20_CONSTEXPR
315 inline _Iterator
316 __niter_base(_Iterator __it)
317 _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
318 { return __it; }
319
320 template<typename _Ite, typename _Seq>
321 _GLIBCXX20_CONSTEXPR
322 _Ite
323 __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
324 std::random_access_iterator_tag>&);
325
326 // Reverse the __niter_base transformation to get a
327 // __normal_iterator back again (this assumes that __normal_iterator
328 // is only used to wrap random access iterators, like pointers).
329 template<typename _From, typename _To>
330 _GLIBCXX20_CONSTEXPR
331 inline _From
332 __niter_wrap(_From __from, _To __res)
333 { return __from + (__res - std::__niter_base(__from)); }
334
335 // No need to wrap, iterator already has the right type.
336 template<typename _Iterator>
337 _GLIBCXX20_CONSTEXPR
338 inline _Iterator
339 __niter_wrap(const _Iterator&, _Iterator __res)
340 { return __res; }
341
342 // All of these auxiliary structs serve two purposes. (1) Replace
343 // calls to copy with memmove whenever possible. (Memmove, not memcpy,
344 // because the input and output ranges are permitted to overlap.)
345 // (2) If we're using random access iterators, then write the loop as
346 // a for loop with an explicit count.
347
348 template<bool _IsMove, bool _IsSimple, typename _Category>
349 struct __copy_move
350 {
351 template<typename _II, typename _OI>
352 _GLIBCXX20_CONSTEXPR
353 static _OI
354 __copy_m(_II __first, _II __last, _OI __result)
355 {
356 for (; __first != __last; ++__result, (void)++__first)
357 *__result = *__first;
358 return __result;
359 }
360 };
361
362 #if __cplusplus >= 201103L
363 template<typename _Category>
364 struct __copy_move<true, false, _Category>
365 {
366 template<typename _II, typename _OI>
367 _GLIBCXX20_CONSTEXPR
368 static _OI
369 __copy_m(_II __first, _II __last, _OI __result)
370 {
371 for (; __first != __last; ++__result, (void)++__first)
372 *__result = std::move(*__first);
373 return __result;
374 }
375 };
376 #endif
377
378 template<>
379 struct __copy_move<false, false, random_access_iterator_tag>
380 {
381 template<typename _II, typename _OI>
382 _GLIBCXX20_CONSTEXPR
383 static _OI
384 __copy_m(_II __first, _II __last, _OI __result)
385 {
386 typedef typename iterator_traits<_II>::difference_type _Distance;
387 for(_Distance __n = __last - __first; __n > 0; --__n)
388 {
389 *__result = *__first;
390 ++__first;
391 ++__result;
392 }
393 return __result;
394 }
395
396 template<typename _Tp, typename _Up>
397 static void
398 __assign_one(_Tp* __to, _Up* __from)
399 { *__to = *__from; }
400 };
401
402 #if __cplusplus >= 201103L
403 template<>
404 struct __copy_move<true, false, random_access_iterator_tag>
405 {
406 template<typename _II, typename _OI>
407 _GLIBCXX20_CONSTEXPR
408 static _OI
409 __copy_m(_II __first, _II __last, _OI __result)
410 {
411 typedef typename iterator_traits<_II>::difference_type _Distance;
412 for(_Distance __n = __last - __first; __n > 0; --__n)
413 {
414 *__result = std::move(*__first);
415 ++__first;
416 ++__result;
417 }
418 return __result;
419 }
420
421 template<typename _Tp, typename _Up>
422 static void
423 __assign_one(_Tp* __to, _Up* __from)
424 { *__to = std::move(*__from); }
425 };
426 #endif
427
428 template<bool _IsMove>
429 struct __copy_move<_IsMove, true, random_access_iterator_tag>
430 {
431 template<typename _Tp, typename _Up>
432 _GLIBCXX20_CONSTEXPR
433 static _Up*
434 __copy_m(_Tp* __first, _Tp* __last, _Up* __result)
435 {
436 const ptrdiff_t _Num = __last - __first;
437 if (__builtin_expect(_Num > 1, true))
438 __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
439 else if (_Num == 1)
440 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
441 __assign_one(__result, __first);
442 return __result + _Num;
443 }
444 };
445
446 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
447
448 template<typename _Tp, typename _Ref, typename _Ptr>
449 struct _Deque_iterator;
450
451 struct _Bit_iterator;
452
453 _GLIBCXX_END_NAMESPACE_CONTAINER
454
455 #if _GLIBCXX_HOSTED
456 // Helpers for streambuf iterators (either istream or ostream).
457 // NB: avoid including <iosfwd>, relatively large.
458 template<typename _CharT>
459 struct char_traits;
460
461 template<typename _CharT, typename _Traits>
462 class istreambuf_iterator;
463
464 template<typename _CharT, typename _Traits>
465 class ostreambuf_iterator;
466
467 template<bool _IsMove, typename _CharT>
468 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
469 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
470 __copy_move_a2(_CharT*, _CharT*,
471 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
472
473 template<bool _IsMove, typename _CharT>
474 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
475 ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
476 __copy_move_a2(const _CharT*, const _CharT*,
477 ostreambuf_iterator<_CharT, char_traits<_CharT> >);
478
479 template<bool _IsMove, typename _CharT>
480 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
481 _CharT*>::__type
482 __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
483 istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
484
485 template<bool _IsMove, typename _CharT>
486 typename __gnu_cxx::__enable_if<
487 __is_char<_CharT>::__value,
488 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
489 __copy_move_a2(
490 istreambuf_iterator<_CharT, char_traits<_CharT> >,
491 istreambuf_iterator<_CharT, char_traits<_CharT> >,
492 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>);
493 #endif // HOSTED
494
495 template<bool _IsMove, typename _II, typename _OI>
496 _GLIBCXX20_CONSTEXPR
497 inline _OI
498 __copy_move_a2(_II __first, _II __last, _OI __result)
499 {
500 typedef typename iterator_traits<_II>::iterator_category _Category;
501 #ifdef __cpp_lib_is_constant_evaluated
502 if (std::is_constant_evaluated())
503 return std::__copy_move<_IsMove, false, _Category>::
504 __copy_m(__first, __last, __result);
505 #endif
506 return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value,
507 _Category>::__copy_m(__first, __last, __result);
508 }
509
510 template<bool _IsMove,
511 typename _Tp, typename _Ref, typename _Ptr, typename _OI>
512 _OI
513 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
514 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
515 _OI);
516
517 template<bool _IsMove,
518 typename _ITp, typename _IRef, typename _IPtr, typename _OTp>
519 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
520 __copy_move_a1(_GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
521 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
522 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
523
524 template<bool _IsMove, typename _II, typename _Tp>
525 typename __gnu_cxx::__enable_if<
526 __is_random_access_iter<_II>::__value,
527 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
528 __copy_move_a1(_II, _II, _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
529
530 template<bool _IsMove, typename _II, typename _OI>
531 _GLIBCXX20_CONSTEXPR
532 inline _OI
533 __copy_move_a1(_II __first, _II __last, _OI __result)
534 { return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
535
536 template<bool _IsMove, typename _II, typename _OI>
537 _GLIBCXX20_CONSTEXPR
538 inline _OI
539 __copy_move_a(_II __first, _II __last, _OI __result)
540 {
541 return std::__niter_wrap(__result,
542 std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
543 std::__niter_base(__last),
544 std::__niter_base(__result)));
545 }
546
547 template<bool _IsMove,
548 typename _Ite, typename _Seq, typename _Cat, typename _OI>
549 _GLIBCXX20_CONSTEXPR
550 _OI
551 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
552 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
553 _OI);
554
555 template<bool _IsMove,
556 typename _II, typename _Ite, typename _Seq, typename _Cat>
557 _GLIBCXX20_CONSTEXPR
558 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
559 __copy_move_a(_II, _II,
560 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
561
562 template<bool _IsMove,
563 typename _IIte, typename _ISeq, typename _ICat,
564 typename _OIte, typename _OSeq, typename _OCat>
565 _GLIBCXX20_CONSTEXPR
566 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
567 __copy_move_a(const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
568 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
569 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
570
571 template<typename _InputIterator, typename _Size, typename _OutputIterator>
572 _GLIBCXX20_CONSTEXPR
573 _OutputIterator
574 __copy_n_a(_InputIterator __first, _Size __n, _OutputIterator __result,
575 bool)
576 {
577 if (__n > 0)
578 {
579 while (true)
580 {
581 *__result = *__first;
582 ++__result;
583 if (--__n > 0)
584 ++__first;
585 else
586 break;
587 }
588 }
589 return __result;
590 }
591
592 #if _GLIBCXX_HOSTED
593 template<typename _CharT, typename _Size>
594 typename __gnu_cxx::__enable_if<
595 __is_char<_CharT>::__value, _CharT*>::__type
596 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >,
597 _Size, _CharT*, bool);
598
599 template<typename _CharT, typename _Size>
600 typename __gnu_cxx::__enable_if<
601 __is_char<_CharT>::__value,
602 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*> >::__type
603 __copy_n_a(istreambuf_iterator<_CharT, char_traits<_CharT> >, _Size,
604 _GLIBCXX_STD_C::_Deque_iterator<_CharT, _CharT&, _CharT*>,
605 bool);
606 #endif
607
608 /**
609 * @brief Copies the range [first,last) into result.
610 * @ingroup mutating_algorithms
611 * @param __first An input iterator.
612 * @param __last An input iterator.
613 * @param __result An output iterator.
614 * @return result + (last - first)
615 *
616 * This inline function will boil down to a call to @c memmove whenever
617 * possible. Failing that, if random access iterators are passed, then the
618 * loop count will be known (and therefore a candidate for compiler
619 * optimizations such as unrolling). Result may not be contained within
620 * [first,last); the copy_backward function should be used instead.
621 *
622 * Note that the end of the output range is permitted to be contained
623 * within [first,last).
624 */
625 template<typename _II, typename _OI>
626 _GLIBCXX20_CONSTEXPR
627 inline _OI
628 copy(_II __first, _II __last, _OI __result)
629 {
630 // concept requirements
631 __glibcxx_function_requires(_InputIteratorConcept<_II>)
632 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
633 typename iterator_traits<_II>::reference>)
634 __glibcxx_requires_can_increment_range(__first, __last, __result);
635
636 return std::__copy_move_a<__is_move_iterator<_II>::__value>
637 (std::__miter_base(__first), std::__miter_base(__last), __result);
638 }
639
640 #if __cplusplus >= 201103L
641 /**
642 * @brief Moves the range [first,last) into result.
643 * @ingroup mutating_algorithms
644 * @param __first An input iterator.
645 * @param __last An input iterator.
646 * @param __result An output iterator.
647 * @return result + (last - first)
648 *
649 * This inline function will boil down to a call to @c memmove whenever
650 * possible. Failing that, if random access iterators are passed, then the
651 * loop count will be known (and therefore a candidate for compiler
652 * optimizations such as unrolling). Result may not be contained within
653 * [first,last); the move_backward function should be used instead.
654 *
655 * Note that the end of the output range is permitted to be contained
656 * within [first,last).
657 */
658 template<typename _II, typename _OI>
659 _GLIBCXX20_CONSTEXPR
660 inline _OI
661 move(_II __first, _II __last, _OI __result)
662 {
663 // concept requirements
664 __glibcxx_function_requires(_InputIteratorConcept<_II>)
665 __glibcxx_function_requires(_OutputIteratorConcept<_OI,
666 typename iterator_traits<_II>::value_type&&>)
667 __glibcxx_requires_can_increment_range(__first, __last, __result);
668
669 return std::__copy_move_a<true>(std::__miter_base(__first),
670 std::__miter_base(__last), __result);
671 }
672
673 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
674 #else
675 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
676 #endif
677
678 template<bool _IsMove, bool _IsSimple, typename _Category>
679 struct __copy_move_backward
680 {
681 template<typename _BI1, typename _BI2>
682 _GLIBCXX20_CONSTEXPR
683 static _BI2
684 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
685 {
686 while (__first != __last)
687 *--__result = *--__last;
688 return __result;
689 }
690 };
691
692 #if __cplusplus >= 201103L
693 template<typename _Category>
694 struct __copy_move_backward<true, false, _Category>
695 {
696 template<typename _BI1, typename _BI2>
697 _GLIBCXX20_CONSTEXPR
698 static _BI2
699 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
700 {
701 while (__first != __last)
702 *--__result = std::move(*--__last);
703 return __result;
704 }
705 };
706 #endif
707
708 template<>
709 struct __copy_move_backward<false, false, random_access_iterator_tag>
710 {
711 template<typename _BI1, typename _BI2>
712 _GLIBCXX20_CONSTEXPR
713 static _BI2
714 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
715 {
716 typename iterator_traits<_BI1>::difference_type
717 __n = __last - __first;
718 for (; __n > 0; --__n)
719 *--__result = *--__last;
720 return __result;
721 }
722 };
723
724 #if __cplusplus >= 201103L
725 template<>
726 struct __copy_move_backward<true, false, random_access_iterator_tag>
727 {
728 template<typename _BI1, typename _BI2>
729 _GLIBCXX20_CONSTEXPR
730 static _BI2
731 __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
732 {
733 typename iterator_traits<_BI1>::difference_type
734 __n = __last - __first;
735 for (; __n > 0; --__n)
736 *--__result = std::move(*--__last);
737 return __result;
738 }
739 };
740 #endif
741
742 template<bool _IsMove>
743 struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
744 {
745 template<typename _Tp, typename _Up>
746 _GLIBCXX20_CONSTEXPR
747 static _Up*
748 __copy_move_b(_Tp* __first, _Tp* __last, _Up* __result)
749 {
750 const ptrdiff_t _Num = __last - __first;
751 if (__builtin_expect(_Num > 1, true))
752 __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
753 else if (_Num == 1)
754 std::__copy_move<_IsMove, false, random_access_iterator_tag>::
755 __assign_one(__result - 1, __first);
756 return __result - _Num;
757 }
758 };
759
760 template<bool _IsMove, typename _BI1, typename _BI2>
761 _GLIBCXX20_CONSTEXPR
762 inline _BI2
763 __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
764 {
765 typedef typename iterator_traits<_BI1>::iterator_category _Category;
766 #ifdef __cpp_lib_is_constant_evaluated
767 if (std::is_constant_evaluated())
768 return std::__copy_move_backward<_IsMove, false, _Category>::
769 __copy_move_b(__first, __last, __result);
770 #endif
771 return std::__copy_move_backward<_IsMove,
772 __memcpyable<_BI2, _BI1>::__value,
773 _Category>::__copy_move_b(__first,
774 __last,
775 __result);
776 }
777
778 template<bool _IsMove, typename _BI1, typename _BI2>
779 _GLIBCXX20_CONSTEXPR
780 inline _BI2
781 __copy_move_backward_a1(_BI1 __first, _BI1 __last, _BI2 __result)
782 { return std::__copy_move_backward_a2<_IsMove>(__first, __last, __result); }
783
784 template<bool _IsMove,
785 typename _Tp, typename _Ref, typename _Ptr, typename _OI>
786 _OI
787 __copy_move_backward_a1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
788 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
789 _OI);
790
791 template<bool _IsMove,
792 typename _ITp, typename _IRef, typename _IPtr, typename _OTp>
793 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>
794 __copy_move_backward_a1(
795 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
796 _GLIBCXX_STD_C::_Deque_iterator<_ITp, _IRef, _IPtr>,
797 _GLIBCXX_STD_C::_Deque_iterator<_OTp, _OTp&, _OTp*>);
798
799 template<bool _IsMove, typename _II, typename _Tp>
800 typename __gnu_cxx::__enable_if<
801 __is_random_access_iter<_II>::__value,
802 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> >::__type
803 __copy_move_backward_a1(_II, _II,
804 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
805
806 template<bool _IsMove, typename _II, typename _OI>
807 _GLIBCXX20_CONSTEXPR
808 inline _OI
809 __copy_move_backward_a(_II __first, _II __last, _OI __result)
810 {
811 return std::__niter_wrap(__result,
812 std::__copy_move_backward_a1<_IsMove>
813 (std::__niter_base(__first), std::__niter_base(__last),
814 std::__niter_base(__result)));
815 }
816
817 template<bool _IsMove,
818 typename _Ite, typename _Seq, typename _Cat, typename _OI>
819 _GLIBCXX20_CONSTEXPR
820 _OI
821 __copy_move_backward_a(
822 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
823 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
824 _OI);
825
826 template<bool _IsMove,
827 typename _II, typename _Ite, typename _Seq, typename _Cat>
828 _GLIBCXX20_CONSTEXPR
829 __gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
830 __copy_move_backward_a(_II, _II,
831 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&);
832
833 template<bool _IsMove,
834 typename _IIte, typename _ISeq, typename _ICat,
835 typename _OIte, typename _OSeq, typename _OCat>
836 _GLIBCXX20_CONSTEXPR
837 ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>
838 __copy_move_backward_a(
839 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
840 const ::__gnu_debug::_Safe_iterator<_IIte, _ISeq, _ICat>&,
841 const ::__gnu_debug::_Safe_iterator<_OIte, _OSeq, _OCat>&);
842
843 /**
844 * @brief Copies the range [first,last) into result.
845 * @ingroup mutating_algorithms
846 * @param __first A bidirectional iterator.
847 * @param __last A bidirectional iterator.
848 * @param __result A bidirectional iterator.
849 * @return result - (last - first)
850 *
851 * The function has the same effect as copy, but starts at the end of the
852 * range and works its way to the start, returning the start of the result.
853 * This inline function will boil down to a call to @c memmove whenever
854 * possible. Failing that, if random access iterators are passed, then the
855 * loop count will be known (and therefore a candidate for compiler
856 * optimizations such as unrolling).
857 *
858 * Result may not be in the range (first,last]. Use copy instead. Note
859 * that the start of the output range may overlap [first,last).
860 */
861 template<typename _BI1, typename _BI2>
862 _GLIBCXX20_CONSTEXPR
863 inline _BI2
864 copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
865 {
866 // concept requirements
867 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
868 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
869 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
870 typename iterator_traits<_BI1>::reference>)
871 __glibcxx_requires_can_decrement_range(__first, __last, __result);
872
873 return std::__copy_move_backward_a<__is_move_iterator<_BI1>::__value>
874 (std::__miter_base(__first), std::__miter_base(__last), __result);
875 }
876
877 #if __cplusplus >= 201103L
878 /**
879 * @brief Moves the range [first,last) into result.
880 * @ingroup mutating_algorithms
881 * @param __first A bidirectional iterator.
882 * @param __last A bidirectional iterator.
883 * @param __result A bidirectional iterator.
884 * @return result - (last - first)
885 *
886 * The function has the same effect as move, but starts at the end of the
887 * range and works its way to the start, returning the start of the result.
888 * This inline function will boil down to a call to @c memmove whenever
889 * possible. Failing that, if random access iterators are passed, then the
890 * loop count will be known (and therefore a candidate for compiler
891 * optimizations such as unrolling).
892 *
893 * Result may not be in the range (first,last]. Use move instead. Note
894 * that the start of the output range may overlap [first,last).
895 */
896 template<typename _BI1, typename _BI2>
897 _GLIBCXX20_CONSTEXPR
898 inline _BI2
899 move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
900 {
901 // concept requirements
902 __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
903 __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
904 __glibcxx_function_requires(_OutputIteratorConcept<_BI2,
905 typename iterator_traits<_BI1>::value_type&&>)
906 __glibcxx_requires_can_decrement_range(__first, __last, __result);
907
908 return std::__copy_move_backward_a<true>(std::__miter_base(__first),
909 std::__miter_base(__last),
910 __result);
911 }
912
913 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
914 #else
915 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
916 #endif
917
918 template<typename _ForwardIterator, typename _Tp>
919 _GLIBCXX20_CONSTEXPR
920 inline typename
921 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
922 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
923 const _Tp& __value)
924 {
925 for (; __first != __last; ++__first)
926 *__first = __value;
927 }
928
929 template<typename _ForwardIterator, typename _Tp>
930 _GLIBCXX20_CONSTEXPR
931 inline typename
932 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
933 __fill_a1(_ForwardIterator __first, _ForwardIterator __last,
934 const _Tp& __value)
935 {
936 const _Tp __tmp = __value;
937 for (; __first != __last; ++__first)
938 *__first = __tmp;
939 }
940
941 // Specialization: for char types we can use memset.
942 template<typename _Tp>
943 _GLIBCXX20_CONSTEXPR
944 inline typename
945 __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
946 __fill_a1(_Tp* __first, _Tp* __last, const _Tp& __c)
947 {
948 const _Tp __tmp = __c;
949 #if __cpp_lib_is_constant_evaluated
950 if (std::is_constant_evaluated())
951 {
952 for (; __first != __last; ++__first)
953 *__first = __tmp;
954 return;
955 }
956 #endif
957 if (const size_t __len = __last - __first)
958 __builtin_memset(__first, static_cast<unsigned char>(__tmp), __len);
959 }
960
961 template<typename _Ite, typename _Cont, typename _Tp>
962 _GLIBCXX20_CONSTEXPR
963 inline void
964 __fill_a1(::__gnu_cxx::__normal_iterator<_Ite, _Cont> __first,
965 ::__gnu_cxx::__normal_iterator<_Ite, _Cont> __last,
966 const _Tp& __value)
967 { std::__fill_a1(__first.base(), __last.base(), __value); }
968
969 template<typename _Tp, typename _VTp>
970 void
971 __fill_a1(const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
972 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
973 const _VTp&);
974
975 _GLIBCXX20_CONSTEXPR
976 void
977 __fill_a1(_GLIBCXX_STD_C::_Bit_iterator, _GLIBCXX_STD_C::_Bit_iterator,
978 const bool&);
979
980 template<typename _FIte, typename _Tp>
981 _GLIBCXX20_CONSTEXPR
982 inline void
983 __fill_a(_FIte __first, _FIte __last, const _Tp& __value)
984 { std::__fill_a1(__first, __last, __value); }
985
986 template<typename _Ite, typename _Seq, typename _Cat, typename _Tp>
987 _GLIBCXX20_CONSTEXPR
988 void
989 __fill_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
990 const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>&,
991 const _Tp&);
992
993 /**
994 * @brief Fills the range [first,last) with copies of value.
995 * @ingroup mutating_algorithms
996 * @param __first A forward iterator.
997 * @param __last A forward iterator.
998 * @param __value A reference-to-const of arbitrary type.
999 * @return Nothing.
1000 *
1001 * This function fills a range with copies of the same value. For char
1002 * types filling contiguous areas of memory, this becomes an inline call
1003 * to @c memset or @c wmemset.
1004 */
1005 template<typename _ForwardIterator, typename _Tp>
1006 _GLIBCXX20_CONSTEXPR
1007 inline void
1008 fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
1009 {
1010 // concept requirements
1011 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
1012 _ForwardIterator>)
1013 __glibcxx_requires_valid_range(__first, __last);
1014
1015 std::__fill_a(__first, __last, __value);
1016 }
1017
1018 // Used by fill_n, generate_n, etc. to convert _Size to an integral type:
1019 inline _GLIBCXX_CONSTEXPR int
1020 __size_to_integer(int __n) { return __n; }
1021 inline _GLIBCXX_CONSTEXPR unsigned
1022 __size_to_integer(unsigned __n) { return __n; }
1023 inline _GLIBCXX_CONSTEXPR long
1024 __size_to_integer(long __n) { return __n; }
1025 inline _GLIBCXX_CONSTEXPR unsigned long
1026 __size_to_integer(unsigned long __n) { return __n; }
1027 inline _GLIBCXX_CONSTEXPR long long
1028 __size_to_integer(long long __n) { return __n; }
1029 inline _GLIBCXX_CONSTEXPR unsigned long long
1030 __size_to_integer(unsigned long long __n) { return __n; }
1031
1032 #if defined(__GLIBCXX_TYPE_INT_N_0)
1033 __extension__ inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0
1034 __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
1035 __extension__ inline _GLIBCXX_CONSTEXPR unsigned __GLIBCXX_TYPE_INT_N_0
1036 __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
1037 #endif
1038 #if defined(__GLIBCXX_TYPE_INT_N_1)
1039 __extension__ inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1
1040 __size_to_integer(__GLIBCXX_TYPE_INT_N_1 __n) { return __n; }
1041 __extension__ inline _GLIBCXX_CONSTEXPR unsigned __GLIBCXX_TYPE_INT_N_1
1042 __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_1 __n) { return __n; }
1043 #endif
1044 #if defined(__GLIBCXX_TYPE_INT_N_2)
1045 __extension__ inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2
1046 __size_to_integer(__GLIBCXX_TYPE_INT_N_2 __n) { return __n; }
1047 __extension__ inline _GLIBCXX_CONSTEXPR unsigned __GLIBCXX_TYPE_INT_N_2
1048 __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_2 __n) { return __n; }
1049 #endif
1050 #if defined(__GLIBCXX_TYPE_INT_N_3)
1051 __extension__ inline _GLIBCXX_CONSTEXPR unsigned __GLIBCXX_TYPE_INT_N_3
1052 __size_to_integer(__GLIBCXX_TYPE_INT_N_3 __n) { return __n; }
1053 __extension__ inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3
1054 __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_3 __n) { return __n; }
1055 #endif
1056
1057 inline _GLIBCXX_CONSTEXPR long long
1058 __size_to_integer(float __n) { return (long long)__n; }
1059 inline _GLIBCXX_CONSTEXPR long long
1060 __size_to_integer(double __n) { return (long long)__n; }
1061 inline _GLIBCXX_CONSTEXPR long long
1062 __size_to_integer(long double __n) { return (long long)__n; }
1063 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
1064 __extension__ inline _GLIBCXX_CONSTEXPR long long
1065 __size_to_integer(__float128 __n) { return (long long)__n; }
1066 #endif
1067
1068 template<typename _OutputIterator, typename _Size, typename _Tp>
1069 _GLIBCXX20_CONSTEXPR
1070 inline typename
1071 __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
1072 __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
1073 {
1074 for (; __n > 0; --__n, (void) ++__first)
1075 *__first = __value;
1076 return __first;
1077 }
1078
1079 template<typename _OutputIterator, typename _Size, typename _Tp>
1080 _GLIBCXX20_CONSTEXPR
1081 inline typename
1082 __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
1083 __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value)
1084 {
1085 const _Tp __tmp = __value;
1086 for (; __n > 0; --__n, (void) ++__first)
1087 *__first = __tmp;
1088 return __first;
1089 }
1090
1091 template<typename _Ite, typename _Seq, typename _Cat, typename _Size,
1092 typename _Tp>
1093 _GLIBCXX20_CONSTEXPR
1094 ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>
1095 __fill_n_a(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, _Cat>& __first,
1096 _Size __n, const _Tp& __value,
1097 std::input_iterator_tag);
1098
1099 template<typename _OutputIterator, typename _Size, typename _Tp>
1100 _GLIBCXX20_CONSTEXPR
1101 inline _OutputIterator
1102 __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value,
1103 std::output_iterator_tag)
1104 {
1105 #if __cplusplus >= 201103L
1106 static_assert(is_integral<_Size>{}, "fill_n must pass integral size");
1107 #endif
1108 return __fill_n_a1(__first, __n, __value);
1109 }
1110
1111 template<typename _OutputIterator, typename _Size, typename _Tp>
1112 _GLIBCXX20_CONSTEXPR
1113 inline _OutputIterator
1114 __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value,
1115 std::input_iterator_tag)
1116 {
1117 #if __cplusplus >= 201103L
1118 static_assert(is_integral<_Size>{}, "fill_n must pass integral size");
1119 #endif
1120 return __fill_n_a1(__first, __n, __value);
1121 }
1122
1123 template<typename _OutputIterator, typename _Size, typename _Tp>
1124 _GLIBCXX20_CONSTEXPR
1125 inline _OutputIterator
1126 __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value,
1127 std::random_access_iterator_tag)
1128 {
1129 #if __cplusplus >= 201103L
1130 static_assert(is_integral<_Size>{}, "fill_n must pass integral size");
1131 #endif
1132 if (__n <= 0)
1133 return __first;
1134
1135 __glibcxx_requires_can_increment(__first, __n);
1136
1137 std::__fill_a(__first, __first + __n, __value);
1138 return __first + __n;
1139 }
1140
1141 /**
1142 * @brief Fills the range [first,first+n) with copies of value.
1143 * @ingroup mutating_algorithms
1144 * @param __first An output iterator.
1145 * @param __n The count of copies to perform.
1146 * @param __value A reference-to-const of arbitrary type.
1147 * @return The iterator at first+n.
1148 *
1149 * This function fills a range with copies of the same value. For char
1150 * types filling contiguous areas of memory, this becomes an inline call
1151 * to @c memset or @c wmemset.
1152 *
1153 * If @p __n is negative, the function does nothing.
1154 */
1155 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1156 // DR 865. More algorithms that throw away information
1157 // DR 426. search_n(), fill_n(), and generate_n() with negative n
1158 template<typename _OI, typename _Size, typename _Tp>
1159 _GLIBCXX20_CONSTEXPR
1160 inline _OI
1161 fill_n(_OI __first, _Size __n, const _Tp& __value)
1162 {
1163 // concept requirements
1164 __glibcxx_function_requires(_OutputIteratorConcept<_OI, const _Tp&>)
1165
1166 return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
1167 std::__iterator_category(__first));
1168 }
1169
1170 template<bool _BoolType>
1171 struct __equal
1172 {
1173 template<typename _II1, typename _II2>
1174 _GLIBCXX20_CONSTEXPR
1175 static bool
1176 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1177 {
1178 for (; __first1 != __last1; ++__first1, (void) ++__first2)
1179 if (!(*__first1 == *__first2))
1180 return false;
1181 return true;
1182 }
1183 };
1184
1185 template<>
1186 struct __equal<true>
1187 {
1188 template<typename _Tp>
1189 _GLIBCXX20_CONSTEXPR
1190 static bool
1191 equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2)
1192 {
1193 if (const size_t __len = (__last1 - __first1))
1194 return !std::__memcmp(__first1, __first2, __len);
1195 return true;
1196 }
1197 };
1198
1199 template<typename _Tp, typename _Ref, typename _Ptr, typename _II>
1200 typename __gnu_cxx::__enable_if<
1201 __is_random_access_iter<_II>::__value, bool>::__type
1202 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1203 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>,
1204 _II);
1205
1206 template<typename _Tp1, typename _Ref1, typename _Ptr1,
1207 typename _Tp2, typename _Ref2, typename _Ptr2>
1208 bool
1209 __equal_aux1(_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1210 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1211 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1212
1213 template<typename _II, typename _Tp, typename _Ref, typename _Ptr>
1214 typename __gnu_cxx::__enable_if<
1215 __is_random_access_iter<_II>::__value, bool>::__type
1216 __equal_aux1(_II, _II,
1217 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Ref, _Ptr>);
1218
1219 template<typename _II1, typename _II2>
1220 _GLIBCXX20_CONSTEXPR
1221 inline bool
1222 __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2)
1223 {
1224 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1225 const bool __simple = ((__is_integer<_ValueType1>::__value
1226 || __is_pointer<_ValueType1>::__value)
1227 && __memcmpable<_II1, _II2>::__value);
1228 return std::__equal<__simple>::equal(__first1, __last1, __first2);
1229 }
1230
1231 template<typename _II1, typename _II2>
1232 _GLIBCXX20_CONSTEXPR
1233 inline bool
1234 __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
1235 {
1236 return std::__equal_aux1(std::__niter_base(__first1),
1237 std::__niter_base(__last1),
1238 std::__niter_base(__first2));
1239 }
1240
1241 template<typename _II1, typename _Seq1, typename _Cat1, typename _II2>
1242 _GLIBCXX20_CONSTEXPR
1243 bool
1244 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1245 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1246 _II2);
1247
1248 template<typename _II1, typename _II2, typename _Seq2, typename _Cat2>
1249 _GLIBCXX20_CONSTEXPR
1250 bool
1251 __equal_aux(_II1, _II1,
1252 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1253
1254 template<typename _II1, typename _Seq1, typename _Cat1,
1255 typename _II2, typename _Seq2, typename _Cat2>
1256 _GLIBCXX20_CONSTEXPR
1257 bool
1258 __equal_aux(const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1259 const ::__gnu_debug::_Safe_iterator<_II1, _Seq1, _Cat1>&,
1260 const ::__gnu_debug::_Safe_iterator<_II2, _Seq2, _Cat2>&);
1261
1262 template<typename, typename>
1263 struct __lc_rai
1264 {
1265 template<typename _II1, typename _II2>
1266 _GLIBCXX20_CONSTEXPR
1267 static _II1
1268 __newlast1(_II1, _II1 __last1, _II2, _II2)
1269 { return __last1; }
1270
1271 template<typename _II>
1272 _GLIBCXX20_CONSTEXPR
1273 static bool
1274 __cnd2(_II __first, _II __last)
1275 { return __first != __last; }
1276 };
1277
1278 template<>
1279 struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
1280 {
1281 template<typename _RAI1, typename _RAI2>
1282 _GLIBCXX20_CONSTEXPR
1283 static _RAI1
1284 __newlast1(_RAI1 __first1, _RAI1 __last1,
1285 _RAI2 __first2, _RAI2 __last2)
1286 {
1287 const typename iterator_traits<_RAI1>::difference_type
1288 __diff1 = __last1 - __first1;
1289 const typename iterator_traits<_RAI2>::difference_type
1290 __diff2 = __last2 - __first2;
1291 return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
1292 }
1293
1294 template<typename _RAI>
1295 static _GLIBCXX20_CONSTEXPR bool
1296 __cnd2(_RAI, _RAI)
1297 { return true; }
1298 };
1299
1300 template<typename _II1, typename _II2, typename _Compare>
1301 _GLIBCXX20_CONSTEXPR
1302 bool
1303 __lexicographical_compare_impl(_II1 __first1, _II1 __last1,
1304 _II2 __first2, _II2 __last2,
1305 _Compare __comp)
1306 {
1307 typedef typename iterator_traits<_II1>::iterator_category _Category1;
1308 typedef typename iterator_traits<_II2>::iterator_category _Category2;
1309 typedef std::__lc_rai<_Category1, _Category2> __rai_type;
1310
1311 __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
1312 for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
1313 ++__first1, (void)++__first2)
1314 {
1315 if (__comp(__first1, __first2))
1316 return true;
1317 if (__comp(__first2, __first1))
1318 return false;
1319 }
1320 return __first1 == __last1 && __first2 != __last2;
1321 }
1322
1323 template<bool _BoolType>
1324 struct __lexicographical_compare
1325 {
1326 template<typename _II1, typename _II2>
1327 _GLIBCXX20_CONSTEXPR
1328 static bool
1329 __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1330 {
1331 using __gnu_cxx::__ops::__iter_less_iter;
1332 return std::__lexicographical_compare_impl(__first1, __last1,
1333 __first2, __last2,
1334 __iter_less_iter());
1335 }
1336
1337 template<typename _II1, typename _II2>
1338 _GLIBCXX20_CONSTEXPR
1339 static int
1340 __3way(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1341 {
1342 while (__first1 != __last1)
1343 {
1344 if (__first2 == __last2)
1345 return +1;
1346 if (*__first1 < *__first2)
1347 return -1;
1348 if (*__first2 < *__first1)
1349 return +1;
1350 ++__first1;
1351 ++__first2;
1352 }
1353 return int(__first2 == __last2) - 1;
1354 }
1355 };
1356
1357 template<>
1358 struct __lexicographical_compare<true>
1359 {
1360 template<typename _Tp, typename _Up>
1361 _GLIBCXX20_CONSTEXPR
1362 static bool
1363 __lc(const _Tp* __first1, const _Tp* __last1,
1364 const _Up* __first2, const _Up* __last2)
1365 { return __3way(__first1, __last1, __first2, __last2) < 0; }
1366
1367 template<typename _Tp, typename _Up>
1368 _GLIBCXX20_CONSTEXPR
1369 static ptrdiff_t
1370 __3way(const _Tp* __first1, const _Tp* __last1,
1371 const _Up* __first2, const _Up* __last2)
1372 {
1373 const size_t __len1 = __last1 - __first1;
1374 const size_t __len2 = __last2 - __first2;
1375 if (const size_t __len = std::min(__len1, __len2))
1376 if (int __result = std::__memcmp(__first1, __first2, __len))
1377 return __result;
1378 return ptrdiff_t(__len1 - __len2);
1379 }
1380 };
1381
1382 template<typename _II1, typename _II2>
1383 _GLIBCXX20_CONSTEXPR
1384 inline bool
1385 __lexicographical_compare_aux1(_II1 __first1, _II1 __last1,
1386 _II2 __first2, _II2 __last2)
1387 {
1388 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1389 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1390 const bool __simple =
1391 (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
1392 && __is_pointer<_II1>::__value
1393 && __is_pointer<_II2>::__value
1394 #if __cplusplus > 201703L && __glibcxx_concepts
1395 // For C++20 iterator_traits<volatile T*>::value_type is non-volatile
1396 // so __is_byte<T> could be true, but we can't use memcmp with
1397 // volatile data.
1398 && !is_volatile_v<remove_reference_t<iter_reference_t<_II1>>>
1399 && !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
1400 #endif
1401 );
1402
1403 return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
1404 __first2, __last2);
1405 }
1406
1407 template<typename _Tp1, typename _Ref1, typename _Ptr1,
1408 typename _Tp2>
1409 bool
1410 __lexicographical_compare_aux1(
1411 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1412 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1413 _Tp2*, _Tp2*);
1414
1415 template<typename _Tp1,
1416 typename _Tp2, typename _Ref2, typename _Ptr2>
1417 bool
1418 __lexicographical_compare_aux1(_Tp1*, _Tp1*,
1419 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1420 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1421
1422 template<typename _Tp1, typename _Ref1, typename _Ptr1,
1423 typename _Tp2, typename _Ref2, typename _Ptr2>
1424 bool
1425 __lexicographical_compare_aux1(
1426 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1427 _GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref1, _Ptr1>,
1428 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>,
1429 _GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2>);
1430
1431 template<typename _II1, typename _II2>
1432 _GLIBCXX20_CONSTEXPR
1433 inline bool
1434 __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
1435 _II2 __first2, _II2 __last2)
1436 {
1437 return std::__lexicographical_compare_aux1(std::__niter_base(__first1),
1438 std::__niter_base(__last1),
1439 std::__niter_base(__first2),
1440 std::__niter_base(__last2));
1441 }
1442
1443 template<typename _Iter1, typename _Seq1, typename _Cat1,
1444 typename _II2>
1445 _GLIBCXX20_CONSTEXPR
1446 bool
1447 __lexicographical_compare_aux(
1448 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1449 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1450 _II2, _II2);
1451
1452 template<typename _II1,
1453 typename _Iter2, typename _Seq2, typename _Cat2>
1454 _GLIBCXX20_CONSTEXPR
1455 bool
1456 __lexicographical_compare_aux(
1457 _II1, _II1,
1458 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1459 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1460
1461 template<typename _Iter1, typename _Seq1, typename _Cat1,
1462 typename _Iter2, typename _Seq2, typename _Cat2>
1463 _GLIBCXX20_CONSTEXPR
1464 bool
1465 __lexicographical_compare_aux(
1466 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1467 const ::__gnu_debug::_Safe_iterator<_Iter1, _Seq1, _Cat1>&,
1468 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&,
1469 const ::__gnu_debug::_Safe_iterator<_Iter2, _Seq2, _Cat2>&);
1470
1471 template<typename _ForwardIterator, typename _Tp, typename _Compare>
1472 _GLIBCXX20_CONSTEXPR
1473 _ForwardIterator
1474 __lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1475 const _Tp& __val, _Compare __comp)
1476 {
1477 typedef typename iterator_traits<_ForwardIterator>::difference_type
1478 _DistanceType;
1479
1480 _DistanceType __len = std::distance(__first, __last);
1481
1482 while (__len > 0)
1483 {
1484 _DistanceType __half = __len >> 1;
1485 _ForwardIterator __middle = __first;
1486 std::advance(__middle, __half);
1487 if (__comp(__middle, __val))
1488 {
1489 __first = __middle;
1490 ++__first;
1491 __len = __len - __half - 1;
1492 }
1493 else
1494 __len = __half;
1495 }
1496 return __first;
1497 }
1498
1499 /**
1500 * @brief Finds the first position in which @a val could be inserted
1501 * without changing the ordering.
1502 * @param __first An iterator.
1503 * @param __last Another iterator.
1504 * @param __val The search term.
1505 * @return An iterator pointing to the first element <em>not less
1506 * than</em> @a val, or end() if every element is less than
1507 * @a val.
1508 * @ingroup binary_search_algorithms
1509 */
1510 template<typename _ForwardIterator, typename _Tp>
1511 _GLIBCXX20_CONSTEXPR
1512 inline _ForwardIterator
1513 lower_bound(_ForwardIterator __first, _ForwardIterator __last,
1514 const _Tp& __val)
1515 {
1516 // concept requirements
1517 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
1518 __glibcxx_function_requires(_LessThanOpConcept<
1519 typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
1520 __glibcxx_requires_partitioned_lower(__first, __last, __val);
1521
1522 return std::__lower_bound(__first, __last, __val,
1523 __gnu_cxx::__ops::__iter_less_val());
1524 }
1525
1526 /// This is a helper function for the sort routines and for random.tcc.
1527 // Precondition: __n > 0.
1528 template<typename _Tp>
1529 inline _GLIBCXX_CONSTEXPR _Tp
1530 __lg(_Tp __n)
1531 {
1532 #if __cplusplus >= 201402L
1533 return std::__bit_width(make_unsigned_t<_Tp>(__n)) - 1;
1534 #else
1535 // Use +__n so it promotes to at least int.
1536 return (sizeof(+__n) * __CHAR_BIT__ - 1)
1537 - (sizeof(+__n) == sizeof(long long)
1538 ? __builtin_clzll(+__n)
1539 : (sizeof(+__n) == sizeof(long)
1540 ? __builtin_clzl(+__n)
1541 : __builtin_clz(+__n)));
1542 #endif
1543 }
1544
1545 _GLIBCXX_BEGIN_NAMESPACE_ALGO
1546
1547 /**
1548 * @brief Tests a range for element-wise equality.
1549 * @ingroup non_mutating_algorithms
1550 * @param __first1 An input iterator.
1551 * @param __last1 An input iterator.
1552 * @param __first2 An input iterator.
1553 * @return A boolean true or false.
1554 *
1555 * This compares the elements of two ranges using @c == and returns true or
1556 * false depending on whether all of the corresponding elements of the
1557 * ranges are equal.
1558 */
1559 template<typename _II1, typename _II2>
1560 _GLIBCXX20_CONSTEXPR
1561 inline bool
1562 equal(_II1 __first1, _II1 __last1, _II2 __first2)
1563 {
1564 // concept requirements
1565 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1566 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1567 __glibcxx_function_requires(_EqualOpConcept<
1568 typename iterator_traits<_II1>::value_type,
1569 typename iterator_traits<_II2>::value_type>)
1570 __glibcxx_requires_can_increment_range(__first1, __last1, __first2);
1571
1572 return std::__equal_aux(__first1, __last1, __first2);
1573 }
1574
1575 /**
1576 * @brief Tests a range for element-wise equality.
1577 * @ingroup non_mutating_algorithms
1578 * @param __first1 An input iterator.
1579 * @param __last1 An input iterator.
1580 * @param __first2 An input iterator.
1581 * @param __binary_pred A binary predicate @link functors
1582 * functor@endlink.
1583 * @return A boolean true or false.
1584 *
1585 * This compares the elements of two ranges using the binary_pred
1586 * parameter, and returns true or
1587 * false depending on whether all of the corresponding elements of the
1588 * ranges are equal.
1589 */
1590 template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
1591 _GLIBCXX20_CONSTEXPR
1592 inline bool
1593 equal(_IIter1 __first1, _IIter1 __last1,
1594 _IIter2 __first2, _BinaryPredicate __binary_pred)
1595 {
1596 // concept requirements
1597 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1598 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1599 __glibcxx_requires_valid_range(__first1, __last1);
1600
1601 for (; __first1 != __last1; ++__first1, (void)++__first2)
1602 if (!bool(__binary_pred(*__first1, *__first2)))
1603 return false;
1604 return true;
1605 }
1606
1607 #if __cplusplus >= 201103L
1608 // 4-iterator version of std::equal<It1, It2> for use in C++11.
1609 template<typename _II1, typename _II2>
1610 _GLIBCXX20_CONSTEXPR
1611 inline bool
1612 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1613 {
1614 using _RATag = random_access_iterator_tag;
1615 using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1616 using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1617 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1618 if (_RAIters())
1619 {
1620 auto __d1 = std::distance(__first1, __last1);
1621 auto __d2 = std::distance(__first2, __last2);
1622 if (__d1 != __d2)
1623 return false;
1624 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2);
1625 }
1626
1627 for (; __first1 != __last1 && __first2 != __last2;
1628 ++__first1, (void)++__first2)
1629 if (!(*__first1 == *__first2))
1630 return false;
1631 return __first1 == __last1 && __first2 == __last2;
1632 }
1633
1634 // 4-iterator version of std::equal<It1, It2, BinaryPred> for use in C++11.
1635 template<typename _II1, typename _II2, typename _BinaryPredicate>
1636 _GLIBCXX20_CONSTEXPR
1637 inline bool
1638 __equal4(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2,
1639 _BinaryPredicate __binary_pred)
1640 {
1641 using _RATag = random_access_iterator_tag;
1642 using _Cat1 = typename iterator_traits<_II1>::iterator_category;
1643 using _Cat2 = typename iterator_traits<_II2>::iterator_category;
1644 using _RAIters = __and_<is_same<_Cat1, _RATag>, is_same<_Cat2, _RATag>>;
1645 if (_RAIters())
1646 {
1647 auto __d1 = std::distance(__first1, __last1);
1648 auto __d2 = std::distance(__first2, __last2);
1649 if (__d1 != __d2)
1650 return false;
1651 return _GLIBCXX_STD_A::equal(__first1, __last1, __first2,
1652 __binary_pred);
1653 }
1654
1655 for (; __first1 != __last1 && __first2 != __last2;
1656 ++__first1, (void)++__first2)
1657 if (!bool(__binary_pred(*__first1, *__first2)))
1658 return false;
1659 return __first1 == __last1 && __first2 == __last2;
1660 }
1661 #endif // C++11
1662
1663 #ifdef __glibcxx_robust_nonmodifying_seq_ops // C++ >= 14
1664 /**
1665 * @brief Tests a range for element-wise equality.
1666 * @ingroup non_mutating_algorithms
1667 * @param __first1 An input iterator.
1668 * @param __last1 An input iterator.
1669 * @param __first2 An input iterator.
1670 * @param __last2 An input iterator.
1671 * @return A boolean true or false.
1672 *
1673 * This compares the elements of two ranges using @c == and returns true or
1674 * false depending on whether all of the corresponding elements of the
1675 * ranges are equal.
1676 */
1677 template<typename _II1, typename _II2>
1678 _GLIBCXX20_CONSTEXPR
1679 inline bool
1680 equal(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
1681 {
1682 // concept requirements
1683 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1684 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1685 __glibcxx_function_requires(_EqualOpConcept<
1686 typename iterator_traits<_II1>::value_type,
1687 typename iterator_traits<_II2>::value_type>)
1688 __glibcxx_requires_valid_range(__first1, __last1);
1689 __glibcxx_requires_valid_range(__first2, __last2);
1690
1691 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2);
1692 }
1693
1694 /**
1695 * @brief Tests a range for element-wise equality.
1696 * @ingroup non_mutating_algorithms
1697 * @param __first1 An input iterator.
1698 * @param __last1 An input iterator.
1699 * @param __first2 An input iterator.
1700 * @param __last2 An input iterator.
1701 * @param __binary_pred A binary predicate @link functors
1702 * functor@endlink.
1703 * @return A boolean true or false.
1704 *
1705 * This compares the elements of two ranges using the binary_pred
1706 * parameter, and returns true or
1707 * false depending on whether all of the corresponding elements of the
1708 * ranges are equal.
1709 */
1710 template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
1711 _GLIBCXX20_CONSTEXPR
1712 inline bool
1713 equal(_IIter1 __first1, _IIter1 __last1,
1714 _IIter2 __first2, _IIter2 __last2, _BinaryPredicate __binary_pred)
1715 {
1716 // concept requirements
1717 __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
1718 __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
1719 __glibcxx_requires_valid_range(__first1, __last1);
1720 __glibcxx_requires_valid_range(__first2, __last2);
1721
1722 return _GLIBCXX_STD_A::__equal4(__first1, __last1, __first2, __last2,
1723 __binary_pred);
1724 }
1725 #endif // __glibcxx_robust_nonmodifying_seq_ops
1726
1727 /**
1728 * @brief Performs @b dictionary comparison on ranges.
1729 * @ingroup sorting_algorithms
1730 * @param __first1 An input iterator.
1731 * @param __last1 An input iterator.
1732 * @param __first2 An input iterator.
1733 * @param __last2 An input iterator.
1734 * @return A boolean true or false.
1735 *
1736 * <em>Returns true if the sequence of elements defined by the range
1737 * [first1,last1) is lexicographically less than the sequence of elements
1738 * defined by the range [first2,last2). Returns false otherwise.</em>
1739 * (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
1740 * then this is an inline call to @c memcmp.
1741 */
1742 template<typename _II1, typename _II2>
1743 _GLIBCXX20_CONSTEXPR
1744 inline bool
1745 lexicographical_compare(_II1 __first1, _II1 __last1,
1746 _II2 __first2, _II2 __last2)
1747 {
1748 #ifdef _GLIBCXX_CONCEPT_CHECKS
1749 // concept requirements
1750 typedef typename iterator_traits<_II1>::value_type _ValueType1;
1751 typedef typename iterator_traits<_II2>::value_type _ValueType2;
1752 #endif
1753 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1754 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1755 __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
1756 __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
1757 __glibcxx_requires_valid_range(__first1, __last1);
1758 __glibcxx_requires_valid_range(__first2, __last2);
1759
1760 return std::__lexicographical_compare_aux(__first1, __last1,
1761 __first2, __last2);
1762 }
1763
1764 /**
1765 * @brief Performs @b dictionary comparison on ranges.
1766 * @ingroup sorting_algorithms
1767 * @param __first1 An input iterator.
1768 * @param __last1 An input iterator.
1769 * @param __first2 An input iterator.
1770 * @param __last2 An input iterator.
1771 * @param __comp A @link comparison_functors comparison functor@endlink.
1772 * @return A boolean true or false.
1773 *
1774 * The same as the four-parameter @c lexicographical_compare, but uses the
1775 * comp parameter instead of @c <.
1776 */
1777 template<typename _II1, typename _II2, typename _Compare>
1778 _GLIBCXX20_CONSTEXPR
1779 inline bool
1780 lexicographical_compare(_II1 __first1, _II1 __last1,
1781 _II2 __first2, _II2 __last2, _Compare __comp)
1782 {
1783 // concept requirements
1784 __glibcxx_function_requires(_InputIteratorConcept<_II1>)
1785 __glibcxx_function_requires(_InputIteratorConcept<_II2>)
1786 __glibcxx_requires_valid_range(__first1, __last1);
1787 __glibcxx_requires_valid_range(__first2, __last2);
1788
1789 return std::__lexicographical_compare_impl
1790 (__first1, __last1, __first2, __last2,
1791 __gnu_cxx::__ops::__iter_comp_iter(__comp));
1792 }
1793
1794 #if __cpp_lib_three_way_comparison
1795 // Iter points to a contiguous range of unsigned narrow character type
1796 // or std::byte, suitable for comparison by memcmp.
1797 template<typename _Iter>
1798 concept __is_byte_iter = contiguous_iterator<_Iter>
1799 && __is_memcmp_ordered<iter_value_t<_Iter>>::__value;
1800
1801 // Return a struct with two members, initialized to the smaller of x and y
1802 // (or x if they compare equal) and the result of the comparison x <=> y.
1803 template<typename _Tp>
1804 constexpr auto
1805 __min_cmp(_Tp __x, _Tp __y)
1806 {
1807 struct _Res {
1808 _Tp _M_min;
1809 decltype(__x <=> __y) _M_cmp;
1810 };
1811 auto __c = __x <=> __y;
1812 if (__c > 0)
1813 return _Res{__y, __c};
1814 return _Res{__x, __c};
1815 }
1816
1817 /**
1818 * @brief Performs dictionary comparison on ranges.
1819 * @ingroup sorting_algorithms
1820 * @param __first1 An input iterator.
1821 * @param __last1 An input iterator.
1822 * @param __first2 An input iterator.
1823 * @param __last2 An input iterator.
1824 * @param __comp A @link comparison_functors comparison functor@endlink.
1825 * @return The comparison category that `__comp(*__first1, *__first2)`
1826 * returns.
1827 */
1828 template<typename _InputIter1, typename _InputIter2, typename _Comp>
1829 constexpr auto
1830 lexicographical_compare_three_way(_InputIter1 __first1,
1831 _InputIter1 __last1,
1832 _InputIter2 __first2,
1833 _InputIter2 __last2,
1834 _Comp __comp)
1835 -> decltype(__comp(*__first1, *__first2))
1836 {
1837 // concept requirements
1838 __glibcxx_function_requires(_InputIteratorConcept<_InputIter1>)
1839 __glibcxx_function_requires(_InputIteratorConcept<_InputIter2>)
1840 __glibcxx_requires_valid_range(__first1, __last1);
1841 __glibcxx_requires_valid_range(__first2, __last2);
1842
1843 using _Cat = decltype(__comp(*__first1, *__first2));
1844 static_assert(same_as<common_comparison_category_t<_Cat>, _Cat>);
1845
1846 if (!std::__is_constant_evaluated())
1847 if constexpr (same_as<_Comp, __detail::_Synth3way>
1848 || same_as<_Comp, compare_three_way>)
1849 if constexpr (__is_byte_iter<_InputIter1>)
1850 if constexpr (__is_byte_iter<_InputIter2>)
1851 {
1852 const auto [__len, __lencmp] = _GLIBCXX_STD_A::
1853 __min_cmp(__last1 - __first1, __last2 - __first2);
1854 if (__len)
1855 {
1856 const auto __c
1857 = __builtin_memcmp(&*__first1, &*__first2, __len) <=> 0;
1858 if (__c != 0)
1859 return __c;
1860 }
1861 return __lencmp;
1862 }
1863
1864 while (__first1 != __last1)
1865 {
1866 if (__first2 == __last2)
1867 return strong_ordering::greater;
1868 if (auto __cmp = __comp(*__first1, *__first2); __cmp != 0)
1869 return __cmp;
1870 ++__first1;
1871 ++__first2;
1872 }
1873 return (__first2 == __last2) <=> true; // See PR 94006
1874 }
1875
1876 template<typename _InputIter1, typename _InputIter2>
1877 constexpr auto
1878 lexicographical_compare_three_way(_InputIter1 __first1,
1879 _InputIter1 __last1,
1880 _InputIter2 __first2,
1881 _InputIter2 __last2)
1882 {
1883 return _GLIBCXX_STD_A::
1884 lexicographical_compare_three_way(__first1, __last1, __first2, __last2,
1885 compare_three_way{});
1886 }
1887 #endif // three_way_comparison
1888
1889 template<typename _InputIterator1, typename _InputIterator2,
1890 typename _BinaryPredicate>
1891 _GLIBCXX20_CONSTEXPR
1892 pair<_InputIterator1, _InputIterator2>
1893 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1894 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1895 {
1896 while (__first1 != __last1 && __binary_pred(__first1, __first2))
1897 {
1898 ++__first1;
1899 ++__first2;
1900 }
1901 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1902 }
1903
1904 /**
1905 * @brief Finds the places in ranges which don't match.
1906 * @ingroup non_mutating_algorithms
1907 * @param __first1 An input iterator.
1908 * @param __last1 An input iterator.
1909 * @param __first2 An input iterator.
1910 * @return A pair of iterators pointing to the first mismatch.
1911 *
1912 * This compares the elements of two ranges using @c == and returns a pair
1913 * of iterators. The first iterator points into the first range, the
1914 * second iterator points into the second range, and the elements pointed
1915 * to by the iterators are not equal.
1916 */
1917 template<typename _InputIterator1, typename _InputIterator2>
1918 _GLIBCXX20_CONSTEXPR
1919 inline pair<_InputIterator1, _InputIterator2>
1920 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1921 _InputIterator2 __first2)
1922 {
1923 // concept requirements
1924 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1925 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1926 __glibcxx_function_requires(_EqualOpConcept<
1927 typename iterator_traits<_InputIterator1>::value_type,
1928 typename iterator_traits<_InputIterator2>::value_type>)
1929 __glibcxx_requires_valid_range(__first1, __last1);
1930
1931 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1932 __gnu_cxx::__ops::__iter_equal_to_iter());
1933 }
1934
1935 /**
1936 * @brief Finds the places in ranges which don't match.
1937 * @ingroup non_mutating_algorithms
1938 * @param __first1 An input iterator.
1939 * @param __last1 An input iterator.
1940 * @param __first2 An input iterator.
1941 * @param __binary_pred A binary predicate @link functors
1942 * functor@endlink.
1943 * @return A pair of iterators pointing to the first mismatch.
1944 *
1945 * This compares the elements of two ranges using the binary_pred
1946 * parameter, and returns a pair
1947 * of iterators. The first iterator points into the first range, the
1948 * second iterator points into the second range, and the elements pointed
1949 * to by the iterators are not equal.
1950 */
1951 template<typename _InputIterator1, typename _InputIterator2,
1952 typename _BinaryPredicate>
1953 _GLIBCXX20_CONSTEXPR
1954 inline pair<_InputIterator1, _InputIterator2>
1955 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1956 _InputIterator2 __first2, _BinaryPredicate __binary_pred)
1957 {
1958 // concept requirements
1959 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
1960 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
1961 __glibcxx_requires_valid_range(__first1, __last1);
1962
1963 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2,
1964 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
1965 }
1966
1967 #if __glibcxx_robust_nonmodifying_seq_ops // C++ >= 14
1968 template<typename _InputIterator1, typename _InputIterator2,
1969 typename _BinaryPredicate>
1970 _GLIBCXX20_CONSTEXPR
1971 pair<_InputIterator1, _InputIterator2>
1972 __mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
1973 _InputIterator2 __first2, _InputIterator2 __last2,
1974 _BinaryPredicate __binary_pred)
1975 {
1976 while (__first1 != __last1 && __first2 != __last2
1977 && __binary_pred(__first1, __first2))
1978 {
1979 ++__first1;
1980 ++__first2;
1981 }
1982 return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
1983 }
1984
1985 /**
1986 * @brief Finds the places in ranges which don't match.
1987 * @ingroup non_mutating_algorithms
1988 * @param __first1 An input iterator.
1989 * @param __last1 An input iterator.
1990 * @param __first2 An input iterator.
1991 * @param __last2 An input iterator.
1992 * @return A pair of iterators pointing to the first mismatch.
1993 *
1994 * This compares the elements of two ranges using @c == and returns a pair
1995 * of iterators. The first iterator points into the first range, the
1996 * second iterator points into the second range, and the elements pointed
1997 * to by the iterators are not equal.
1998 */
1999 template<typename _InputIterator1, typename _InputIterator2>
2000 _GLIBCXX20_CONSTEXPR
2001 inline pair<_InputIterator1, _InputIterator2>
2002 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2003 _InputIterator2 __first2, _InputIterator2 __last2)
2004 {
2005 // concept requirements
2006 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2007 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2008 __glibcxx_function_requires(_EqualOpConcept<
2009 typename iterator_traits<_InputIterator1>::value_type,
2010 typename iterator_traits<_InputIterator2>::value_type>)
2011 __glibcxx_requires_valid_range(__first1, __last1);
2012 __glibcxx_requires_valid_range(__first2, __last2);
2013
2014 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2015 __gnu_cxx::__ops::__iter_equal_to_iter());
2016 }
2017
2018 /**
2019 * @brief Finds the places in ranges which don't match.
2020 * @ingroup non_mutating_algorithms
2021 * @param __first1 An input iterator.
2022 * @param __last1 An input iterator.
2023 * @param __first2 An input iterator.
2024 * @param __last2 An input iterator.
2025 * @param __binary_pred A binary predicate @link functors
2026 * functor@endlink.
2027 * @return A pair of iterators pointing to the first mismatch.
2028 *
2029 * This compares the elements of two ranges using the binary_pred
2030 * parameter, and returns a pair
2031 * of iterators. The first iterator points into the first range, the
2032 * second iterator points into the second range, and the elements pointed
2033 * to by the iterators are not equal.
2034 */
2035 template<typename _InputIterator1, typename _InputIterator2,
2036 typename _BinaryPredicate>
2037 _GLIBCXX20_CONSTEXPR
2038 inline pair<_InputIterator1, _InputIterator2>
2039 mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
2040 _InputIterator2 __first2, _InputIterator2 __last2,
2041 _BinaryPredicate __binary_pred)
2042 {
2043 // concept requirements
2044 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
2045 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
2046 __glibcxx_requires_valid_range(__first1, __last1);
2047 __glibcxx_requires_valid_range(__first2, __last2);
2048
2049 return _GLIBCXX_STD_A::__mismatch(__first1, __last1, __first2, __last2,
2050 __gnu_cxx::__ops::__iter_comp_iter(__binary_pred));
2051 }
2052 #endif
2053
2054 _GLIBCXX_END_NAMESPACE_ALGO
2055
2056 /// This is an overload used by find algos for the Input Iterator case.
2057 template<typename _InputIterator, typename _Predicate>
2058 _GLIBCXX20_CONSTEXPR
2059 inline _InputIterator
2060 __find_if(_InputIterator __first, _InputIterator __last,
2061 _Predicate __pred, input_iterator_tag)
2062 {
2063 while (__first != __last && !__pred(__first))
2064 ++__first;
2065 return __first;
2066 }
2067
2068 /// This is an overload used by find algos for the RAI case.
2069 template<typename _RandomAccessIterator, typename _Predicate>
2070 _GLIBCXX20_CONSTEXPR
2071 _RandomAccessIterator
2072 __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
2073 _Predicate __pred, random_access_iterator_tag)
2074 {
2075 typename iterator_traits<_RandomAccessIterator>::difference_type
2076 __trip_count = (__last - __first) >> 2;
2077
2078 for (; __trip_count > 0; --__trip_count)
2079 {
2080 if (__pred(__first))
2081 return __first;
2082 ++__first;
2083
2084 if (__pred(__first))
2085 return __first;
2086 ++__first;
2087
2088 if (__pred(__first))
2089 return __first;
2090 ++__first;
2091
2092 if (__pred(__first))
2093 return __first;
2094 ++__first;
2095 }
2096
2097 switch (__last - __first)
2098 {
2099 case 3:
2100 if (__pred(__first))
2101 return __first;
2102 ++__first;
2103 // FALLTHRU
2104 case 2:
2105 if (__pred(__first))
2106 return __first;
2107 ++__first;
2108 // FALLTHRU
2109 case 1:
2110 if (__pred(__first))
2111 return __first;
2112 ++__first;
2113 // FALLTHRU
2114 case 0:
2115 default:
2116 return __last;
2117 }
2118 }
2119
2120 template<typename _Iterator, typename _Predicate>
2121 _GLIBCXX20_CONSTEXPR
2122 inline _Iterator
2123 __find_if(_Iterator __first, _Iterator __last, _Predicate __pred)
2124 {
2125 return __find_if(__first, __last, __pred,
2126 std::__iterator_category(__first));
2127 }
2128
2129 template<typename _InputIterator, typename _Predicate>
2130 _GLIBCXX20_CONSTEXPR
2131 typename iterator_traits<_InputIterator>::difference_type
2132 __count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
2133 {
2134 typename iterator_traits<_InputIterator>::difference_type __n = 0;
2135 for (; __first != __last; ++__first)
2136 if (__pred(__first))
2137 ++__n;
2138 return __n;
2139 }
2140
2141 template<typename _ForwardIterator, typename _Predicate>
2142 _GLIBCXX20_CONSTEXPR
2143 _ForwardIterator
2144 __remove_if(_ForwardIterator __first, _ForwardIterator __last,
2145 _Predicate __pred)
2146 {
2147 __first = std::__find_if(__first, __last, __pred);
2148 if (__first == __last)
2149 return __first;
2150 _ForwardIterator __result = __first;
2151 ++__first;
2152 for (; __first != __last; ++__first)
2153 if (!__pred(__first))
2154 {
2155 *__result = _GLIBCXX_MOVE(*__first);
2156 ++__result;
2157 }
2158 return __result;
2159 }
2160
2161 template<typename _ForwardIterator1, typename _ForwardIterator2,
2162 typename _BinaryPredicate>
2163 _GLIBCXX20_CONSTEXPR
2164 _ForwardIterator1
2165 __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2166 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2167 _BinaryPredicate __predicate)
2168 {
2169 // Test for empty ranges
2170 if (__first1 == __last1 || __first2 == __last2)
2171 return __first1;
2172
2173 // Test for a pattern of length 1.
2174 _ForwardIterator2 __p1(__first2);
2175 if (++__p1 == __last2)
2176 return std::__find_if(__first1, __last1,
2177 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2178
2179 // General case.
2180 _ForwardIterator1 __current = __first1;
2181
2182 for (;;)
2183 {
2184 __first1 =
2185 std::__find_if(__first1, __last1,
2186 __gnu_cxx::__ops::__iter_comp_iter(__predicate, __first2));
2187
2188 if (__first1 == __last1)
2189 return __last1;
2190
2191 _ForwardIterator2 __p = __p1;
2192 __current = __first1;
2193 if (++__current == __last1)
2194 return __last1;
2195
2196 while (__predicate(__current, __p))
2197 {
2198 if (++__p == __last2)
2199 return __first1;
2200 if (++__current == __last1)
2201 return __last1;
2202 }
2203 ++__first1;
2204 }
2205 return __first1;
2206 }
2207
2208 #if __cplusplus >= 201103L
2209 template<typename _ForwardIterator1, typename _ForwardIterator2,
2210 typename _BinaryPredicate>
2211 _GLIBCXX20_CONSTEXPR
2212 bool
2213 __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2214 _ForwardIterator2 __first2, _BinaryPredicate __pred)
2215 {
2216 // Efficiently compare identical prefixes: O(N) if sequences
2217 // have the same elements in the same order.
2218 for (; __first1 != __last1; ++__first1, (void)++__first2)
2219 if (!__pred(__first1, __first2))
2220 break;
2221
2222 if (__first1 == __last1)
2223 return true;
2224
2225 // Establish __last2 assuming equal ranges by iterating over the
2226 // rest of the list.
2227 _ForwardIterator2 __last2 = __first2;
2228 std::advance(__last2, std::distance(__first1, __last1));
2229 for (_ForwardIterator1 __scan = __first1; __scan != __last1; ++__scan)
2230 {
2231 if (__scan != std::__find_if(__first1, __scan,
2232 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan)))
2233 continue; // We've seen this one before.
2234
2235 auto __matches
2236 = std::__count_if(__first2, __last2,
2237 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan));
2238 if (0 == __matches ||
2239 std::__count_if(__scan, __last1,
2240 __gnu_cxx::__ops::__iter_comp_iter(__pred, __scan))
2241 != __matches)
2242 return false;
2243 }
2244 return true;
2245 }
2246
2247 /**
2248 * @brief Checks whether a permutation of the second sequence is equal
2249 * to the first sequence.
2250 * @ingroup non_mutating_algorithms
2251 * @param __first1 Start of first range.
2252 * @param __last1 End of first range.
2253 * @param __first2 Start of second range.
2254 * @return true if there exists a permutation of the elements in the range
2255 * [__first2, __first2 + (__last1 - __first1)), beginning with
2256 * ForwardIterator2 begin, such that equal(__first1, __last1, begin)
2257 * returns true; otherwise, returns false.
2258 */
2259 template<typename _ForwardIterator1, typename _ForwardIterator2>
2260 _GLIBCXX20_CONSTEXPR
2261 inline bool
2262 is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2263 _ForwardIterator2 __first2)
2264 {
2265 // concept requirements
2266 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2267 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2268 __glibcxx_function_requires(_EqualOpConcept<
2269 typename iterator_traits<_ForwardIterator1>::value_type,
2270 typename iterator_traits<_ForwardIterator2>::value_type>)
2271 __glibcxx_requires_valid_range(__first1, __last1);
2272
2273 return std::__is_permutation(__first1, __last1, __first2,
2274 __gnu_cxx::__ops::__iter_equal_to_iter());
2275 }
2276 #endif // C++11
2277
2278 _GLIBCXX_BEGIN_NAMESPACE_ALGO
2279
2280 /**
2281 * @brief Search a sequence for a matching sub-sequence using a predicate.
2282 * @ingroup non_mutating_algorithms
2283 * @param __first1 A forward iterator.
2284 * @param __last1 A forward iterator.
2285 * @param __first2 A forward iterator.
2286 * @param __last2 A forward iterator.
2287 * @param __predicate A binary predicate.
2288 * @return The first iterator @c i in the range
2289 * @p [__first1,__last1-(__last2-__first2)) such that
2290 * @p __predicate(*(i+N),*(__first2+N)) is true for each @c N in the range
2291 * @p [0,__last2-__first2), or @p __last1 if no such iterator exists.
2292 *
2293 * Searches the range @p [__first1,__last1) for a sub-sequence that
2294 * compares equal value-by-value with the sequence given by @p
2295 * [__first2,__last2), using @p __predicate to determine equality,
2296 * and returns an iterator to the first element of the
2297 * sub-sequence, or @p __last1 if no such iterator exists.
2298 *
2299 * @see search(_ForwardIter1, _ForwardIter1, _ForwardIter2, _ForwardIter2)
2300 */
2301 template<typename _ForwardIterator1, typename _ForwardIterator2,
2302 typename _BinaryPredicate>
2303 _GLIBCXX20_CONSTEXPR
2304 inline _ForwardIterator1
2305 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2306 _ForwardIterator2 __first2, _ForwardIterator2 __last2,
2307 _BinaryPredicate __predicate)
2308 {
2309 // concept requirements
2310 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
2311 __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
2312 __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
2313 typename iterator_traits<_ForwardIterator1>::value_type,
2314 typename iterator_traits<_ForwardIterator2>::value_type>)
2315 __glibcxx_requires_valid_range(__first1, __last1);
2316 __glibcxx_requires_valid_range(__first2, __last2);
2317
2318 return std::__search(__first1, __last1, __first2, __last2,
2319 __gnu_cxx::__ops::__iter_comp_iter(__predicate));
2320 }
2321
2322 _GLIBCXX_END_NAMESPACE_ALGO
2323 _GLIBCXX_END_NAMESPACE_VERSION
2324 } // namespace std
2325
2326 // NB: This file is included within many other C++ includes, as a way
2327 // of getting the base algorithms. So, make sure that parallel bits
2328 // come in too if requested.
2329 #ifdef _GLIBCXX_PARALLEL
2330 # include <parallel/algobase.h>
2331 #endif
2332
2333 #endif