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