libstdc++
Sorting
Collaboration diagram for Sorting:

Topics

 Binary Search
 
 Heap
 
 Set Operations
 

Functions

template<typename _Tp>
constexpr const _Tp & std::clamp (const _Tp &__val, const _Tp &__lo, const _Tp &__hi)
 
template<typename _Tp, typename _Compare>
constexpr const _Tp & std::clamp (const _Tp &__val, const _Tp &__lo, const _Tp &__hi, _Compare __comp)
 
template<typename _BidirectionalIterator>
void std::inplace_merge (_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
 
template<typename _BidirectionalIterator, typename _Compare>
void std::inplace_merge (_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare __comp)
 
template<typename _ForwardIterator>
constexpr bool std::is_sorted (_ForwardIterator __first, _ForwardIterator __last)
 
template<typename _ForwardIterator, typename _Compare>
constexpr bool std::is_sorted (_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 
template<typename _ForwardIterator>
constexpr _ForwardIterator std::is_sorted_until (_ForwardIterator __first, _ForwardIterator __last)
 
template<typename _ForwardIterator, typename _Compare>
constexpr _ForwardIterator std::is_sorted_until (_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 
template<typename _II1, typename _II2>
constexpr bool std::lexicographical_compare (_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
 
template<typename _II1, typename _II2, typename _Compare>
constexpr bool std::lexicographical_compare (_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2, _Compare __comp)
 
template<typename _InputIter1, typename _InputIter2, typename _Comp>
constexpr auto std::lexicographical_compare_three_way (_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _Comp __comp) -> decltype(__comp(*__first1, *__first2))
 
template<typename _Tp>
constexpr const _Tp & std::max (const _Tp &__a, const _Tp &__b)
 
template<typename _Tp, typename _Compare>
constexpr const _Tp & std::max (const _Tp &__a, const _Tp &__b, _Compare __comp)
 
template<typename _ForwardIterator>
constexpr _ForwardIterator std::max_element (_ForwardIterator __first, _ForwardIterator __last)
 
template<typename _ForwardIterator, typename _Compare>
constexpr _ForwardIterator std::max_element (_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 
template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator>
constexpr _OutputIterator std::merge (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
 
template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare>
constexpr _OutputIterator std::merge (_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
 
template<typename _Tp>
constexpr const _Tp & std::min (const _Tp &__a, const _Tp &__b)
 
template<typename _Tp, typename _Compare>
constexpr const _Tp & std::min (const _Tp &__a, const _Tp &__b, _Compare __comp)
 
template<typename _ForwardIterator>
constexpr _ForwardIterator std::min_element (_ForwardIterator __first, _ForwardIterator __last)
 
template<typename _ForwardIterator, typename _Compare>
constexpr _ForwardIterator std::min_element (_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 
template<typename _Tp>
constexpr pair< const _Tp &, const _Tp & > std::minmax (const _Tp &__a, const _Tp &__b)
 
template<typename _Tp, typename _Compare>
constexpr pair< const _Tp &, const _Tp & > std::minmax (const _Tp &__a, const _Tp &__b, _Compare __comp)
 
template<typename _ForwardIterator>
constexpr pair< _ForwardIterator, _ForwardIterator > std::minmax_element (_ForwardIterator __first, _ForwardIterator __last)
 
template<typename _ForwardIterator, typename _Compare>
constexpr pair< _ForwardIterator, _ForwardIterator > std::minmax_element (_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 
template<typename _BidirectionalIterator>
constexpr bool std::next_permutation (_BidirectionalIterator __first, _BidirectionalIterator __last)
 
template<typename _BidirectionalIterator, typename _Compare>
constexpr bool std::next_permutation (_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
 
template<typename _RandomAccessIterator>
constexpr void std::nth_element (_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
 
template<typename _RandomAccessIterator, typename _Compare>
constexpr void std::nth_element (_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
 
template<typename _RandomAccessIterator>
constexpr void std::partial_sort (_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
 
template<typename _RandomAccessIterator, typename _Compare>
constexpr void std::partial_sort (_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
 
template<typename _InputIterator, typename _RandomAccessIterator>
constexpr _RandomAccessIterator std::partial_sort_copy (_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
 
template<typename _InputIterator, typename _RandomAccessIterator, typename _Compare>
constexpr _RandomAccessIterator std::partial_sort_copy (_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
 
template<typename _BidirectionalIterator>
constexpr bool std::prev_permutation (_BidirectionalIterator __first, _BidirectionalIterator __last)
 
template<typename _BidirectionalIterator, typename _Compare>
constexpr bool std::prev_permutation (_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
 
template<typename _RandomAccessIterator>
constexpr void std::sort (_RandomAccessIterator __first, _RandomAccessIterator __last)
 
template<typename _RandomAccessIterator, typename _Compare>
constexpr void std::sort (_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 
template<typename _RandomAccessIterator>
void std::stable_sort (_RandomAccessIterator __first, _RandomAccessIterator __last)
 
template<typename _RandomAccessIterator, typename _Compare>
void std::stable_sort (_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 

Detailed Description

Function Documentation

◆ clamp() [1/2]

template<typename _Tp>
const _Tp & std::clamp ( const _Tp & __val,
const _Tp & __lo,
const _Tp & __hi )
nodiscardconstexpr

Returns the value clamped between lo and hi.

Parameters
__valA value of arbitrary type.
__loA lower limit of arbitrary type.
__hiAn upper limit of arbitrary type.
Return values
`__lo`if __val < __lo
`__hi`if __hi < __val
`__val`otherwise.
Precondition
_Tp is LessThanComparable and (__hi < __lo) is false.

Definition at line 3635 of file stl_algo.h.

References max(), and min().

◆ clamp() [2/2]

template<typename _Tp, typename _Compare>
const _Tp & std::clamp ( const _Tp & __val,
const _Tp & __lo,
const _Tp & __hi,
_Compare __comp )
nodiscardconstexpr

Returns the value clamped between lo and hi.

Parameters
__valA value of arbitrary type.
__loA lower limit of arbitrary type.
__hiAn upper limit of arbitrary type.
__compA comparison functor.
Return values
`__lo`if __comp(__val, __lo)
`__hi`if __comp(__hi, __val)
`__val`otherwise.
Precondition
__comp(__hi, __lo) is false.

Definition at line 3655 of file stl_algo.h.

References max(), and min().

◆ inplace_merge() [1/2]

template<typename _BidirectionalIterator>
void std::inplace_merge ( _BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last )
inline

Merges two sorted ranges in place.

Parameters
__firstAn iterator.
__middleAnother iterator.
__lastAnother iterator.
Returns
Nothing.

Merges two sorted and consecutive ranges, [__first,__middle) and [__middle,__last), and puts the result in [__first,__last). The output will be sorted. The sort is stable, that is, for equivalent elements in the two ranges, elements from the first range will always come before elements from the second.

If enough additional memory is available, this takes (__last-__first)-1 comparisons. Otherwise an NlogN algorithm is used, where N is distance(__first,__last).

Definition at line 2551 of file stl_algo.h.

◆ inplace_merge() [2/2]

template<typename _BidirectionalIterator, typename _Compare>
void std::inplace_merge ( _BidirectionalIterator __first,
_BidirectionalIterator __middle,
_BidirectionalIterator __last,
_Compare __comp )
inline

Merges two sorted ranges in place.

Parameters
__firstAn iterator.
__middleAnother iterator.
__lastAnother iterator.
__compA functor to use for comparisons.
Returns
Nothing.

Merges two sorted and consecutive ranges, [__first,__middle) and [middle,last), and puts the result in [__first,__last). The output will be sorted. The sort is stable, that is, for equivalent elements in the two ranges, elements from the first range will always come before elements from the second.

If enough additional memory is available, this takes (__last-__first)-1 comparisons. Otherwise an NlogN algorithm is used, where N is distance(__first,__last).

The comparison function should have the same effects on ordering as the function used for the initial sort.

Definition at line 2593 of file stl_algo.h.

◆ is_sorted() [1/2]

template<typename _ForwardIterator>
bool std::is_sorted ( _ForwardIterator __first,
_ForwardIterator __last )
inlinenodiscardconstexpr

Determines whether the elements of a sequence are sorted.

Parameters
__firstAn iterator.
__lastAnother iterator.
Returns
True if the elements are sorted, false otherwise.

Definition at line 3202 of file stl_algo.h.

◆ is_sorted() [2/2]

template<typename _ForwardIterator, typename _Compare>
bool std::is_sorted ( _ForwardIterator __first,
_ForwardIterator __last,
_Compare __comp )
inlinenodiscardconstexpr

Determines whether the elements of a sequence are sorted according to a comparison functor.

Parameters
__firstAn iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
True if the elements are sorted, false otherwise.

Definition at line 3217 of file stl_algo.h.

◆ is_sorted_until() [1/2]

template<typename _ForwardIterator>
_ForwardIterator std::is_sorted_until ( _ForwardIterator __first,
_ForwardIterator __last )
inlinenodiscardconstexpr

Determines the end of a sorted sequence.

Parameters
__firstAn iterator.
__lastAnother iterator.
Returns
An iterator pointing to the last iterator i in [__first, __last) for which the range [__first, i) is sorted.

Definition at line 3248 of file stl_algo.h.

◆ is_sorted_until() [2/2]

template<typename _ForwardIterator, typename _Compare>
_ForwardIterator std::is_sorted_until ( _ForwardIterator __first,
_ForwardIterator __last,
_Compare __comp )
inlinenodiscardconstexpr

Determines the end of a sorted sequence using comparison functor.

Parameters
__firstAn iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
An iterator pointing to the last iterator i in [__first, __last) for which the range [__first, i) is sorted.

Definition at line 3273 of file stl_algo.h.

◆ lexicographical_compare() [1/2]

template<typename _II1, typename _II2>
bool std::lexicographical_compare ( _II1 __first1,
_II1 __last1,
_II2 __first2,
_II2 __last2 )
inlinenodiscardconstexpr

Performs dictionary comparison on ranges.

Parameters
__first1An input iterator.
__last1An input iterator.
__first2An input iterator.
__last2An input iterator.
Returns
A boolean true or false.

Returns true if the sequence of elements defined by the range [first1,last1) is lexicographically less than the sequence of elements defined by the range [first2,last2). Returns false otherwise. (Quoted from [25.3.8]/1.) If the iterators are all character pointers, then this is an inline call to memcmp.

Definition at line 1781 of file stl_algobase.h.

◆ lexicographical_compare() [2/2]

template<typename _II1, typename _II2, typename _Compare>
bool std::lexicographical_compare ( _II1 __first1,
_II1 __last1,
_II2 __first2,
_II2 __last2,
_Compare __comp )
inlinenodiscardconstexpr

Performs dictionary comparison on ranges.

Parameters
__first1An input iterator.
__last1An input iterator.
__first2An input iterator.
__last2An input iterator.
__compA comparison functor.
Returns
A boolean true or false.

The same as the four-parameter lexicographical_compare, but uses the comp parameter instead of <.

Definition at line 1816 of file stl_algobase.h.

◆ lexicographical_compare_three_way()

template<typename _InputIter1, typename _InputIter2, typename _Comp>
auto std::lexicographical_compare_three_way ( _InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2,
_InputIter2 __last2,
_Comp __comp ) -> decltype(__comp(*__first1, *__first2))
nodiscardconstexpr

Performs dictionary comparison on ranges.

Parameters
__first1An input iterator.
__last1An input iterator.
__first2An input iterator.
__last2An input iterator.
__compA comparison functor.
Returns
The comparison category that __comp(*__first1, *__first2) returns.

Definition at line 1869 of file stl_algobase.h.

Referenced by operator<=>().

◆ max() [1/2]

template<typename _Tp>
const _Tp & std::max ( const _Tp & __a,
const _Tp & __b )
inlinenodiscardconstexpr

◆ max() [2/2]

template<typename _Tp, typename _Compare>
const _Tp & std::max ( const _Tp & __a,
const _Tp & __b,
_Compare __comp )
inlinenodiscardconstexpr

This does what you think it does.

Parameters
__aA thing of arbitrary type.
__bAnother thing of arbitrary type.
__compA comparison functor.
Returns
The greater of the parameters.

This will work on temporary expressions, since they are only evaluated once, unlike a preprocessor macro.

Definition at line 304 of file stl_algobase.h.

◆ max_element() [1/2]

template<typename _ForwardIterator>
_ForwardIterator std::max_element ( _ForwardIterator __first,
_ForwardIterator __last )
inlinenodiscardconstexpr

Return the maximum element in a range.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
Iterator referencing the first instance of the largest value.

Definition at line 5719 of file stl_algo.h.

◆ max_element() [2/2]

template<typename _ForwardIterator, typename _Compare>
_ForwardIterator std::max_element ( _ForwardIterator __first,
_ForwardIterator __last,
_Compare __comp )
inlinenodiscardconstexpr

Return the maximum element in a range using comparison functor.

Parameters
__firstStart of range.
__lastEnd of range.
__compComparison functor.
Returns
Iterator referencing the first instance of the largest value according to __comp.

Definition at line 5744 of file stl_algo.h.

◆ merge() [1/2]

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator>
_OutputIterator std::merge ( _InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result )
inlineconstexpr

Merges two sorted ranges.

Parameters
__first1An iterator.
__first2Another iterator.
__last1Another iterator.
__last2Another iterator.
__resultAn iterator pointing to the end of the merged range.
Returns
An output iterator equal to __result + (__last1 - __first1)
  • (__last2 - __first2).

Merges the ranges [__first1,__last1) and [__first2,__last2) into the sorted range [__result, __result + (__last1-__first1) + (__last2-__first2)). Both input ranges must be sorted, and the output range must not overlap with either of the input ranges. The sort is stable, that is, for equivalent elements in the two ranges, elements from the first range will always come before elements from the second.

Definition at line 4926 of file stl_algo.h.

◆ merge() [2/2]

template<typename _InputIterator1, typename _InputIterator2, typename _OutputIterator, typename _Compare>
_OutputIterator std::merge ( _InputIterator1 __first1,
_InputIterator1 __last1,
_InputIterator2 __first2,
_InputIterator2 __last2,
_OutputIterator __result,
_Compare __comp )
inlineconstexpr

Merges two sorted ranges.

Parameters
__first1An iterator.
__first2Another iterator.
__last1Another iterator.
__last2Another iterator.
__resultAn iterator pointing to the end of the merged range.
__compA functor to use for comparisons.
Returns
An output iterator equal to __result + (__last1 - __first1)
  • (__last2 - __first2).

Merges the ranges [__first1,__last1) and [__first2,__last2) into the sorted range [__result, __result + (__last1-__first1) + (__last2-__first2)). Both input ranges must be sorted, and the output range must not overlap with either of the input ranges. The sort is stable, that is, for equivalent elements in the two ranges, elements from the first range will always come before elements from the second.

The comparison function should have the same effects on ordering as the function used for the initial sort.

Definition at line 4977 of file stl_algo.h.

◆ min() [1/2]

template<typename _Tp>
const _Tp & std::min ( const _Tp & __a,
const _Tp & __b )
inlinenodiscardconstexpr

This does what you think it does.

Parameters
__aA thing of arbitrary type.
__bAnother thing of arbitrary type.
Returns
The lesser of the parameters.

This is the simple classic generic implementation. It will work on temporary expressions, since they are only evaluated once, unlike a preprocessor macro.

Definition at line 234 of file stl_algobase.h.

Referenced by __gnu_parallel::__find_template(), __gnu_parallel::__find_template(), __gnu_parallel::__for_each_template_random_access_omp_loop_static(), __gnu_parallel::__parallel_partial_sum_linear(), __gnu_parallel::__parallel_random_shuffle_drs(), __gnu_parallel::__parallel_sort_qs_divide(), __gnu_parallel::__qsb_conquer(), __sample(), __gnu_parallel::__search_template(), __gnu_parallel::__sequential_multiway_merge(), __gnu_parallel::__sequential_random_shuffle(), clamp(), clamp(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::compare(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::compare(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::compare(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::compare(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::compare(), __gnu_cxx::__versa_string< char >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), std::basic_string< _CharT >::compare(), generate_canonical(), std::basic_string< _CharT >::max_size(), __gnu_parallel::multiseq_partition(), __gnu_parallel::multiseq_selection(), std::shuffle_order_engine< _RandomNumberEngine, __k >::operator()(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), __gnu_parallel::parallel_multiway_merge(), std::basic_istream< _CharT, _Traits >::readsome(), __gnu_cxx::__versa_string< _CharT, _Traits, _Alloc, _Base >::rfind(), std::basic_string< _CharT, _Traits, _Alloc >::rfind(), std::basic_streambuf< _CharT, _Traits >::xsgetn(), and std::basic_streambuf< _CharT, _Traits >::xsputn().

◆ min() [2/2]

template<typename _Tp, typename _Compare>
const _Tp & std::min ( const _Tp & __a,
const _Tp & __b,
_Compare __comp )
inlinenodiscardconstexpr

This does what you think it does.

Parameters
__aA thing of arbitrary type.
__bAnother thing of arbitrary type.
__compA comparison functor.
Returns
The lesser of the parameters.

This will work on temporary expressions, since they are only evaluated once, unlike a preprocessor macro.

Definition at line 282 of file stl_algobase.h.

◆ min_element() [1/2]

template<typename _ForwardIterator>
_ForwardIterator std::min_element ( _ForwardIterator __first,
_ForwardIterator __last )
inlinenodiscardconstexpr

Return the minimum element in a range.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
Iterator referencing the first instance of the smallest value.

Definition at line 5655 of file stl_algo.h.

◆ min_element() [2/2]

template<typename _ForwardIterator, typename _Compare>
_ForwardIterator std::min_element ( _ForwardIterator __first,
_ForwardIterator __last,
_Compare __comp )
inlinenodiscardconstexpr

Return the minimum element in a range using comparison functor.

Parameters
__firstStart of range.
__lastEnd of range.
__compComparison functor.
Returns
Iterator referencing the first instance of the smallest value according to __comp.

Definition at line 5680 of file stl_algo.h.

◆ minmax() [1/2]

template<typename _Tp>
pair< const _Tp &, const _Tp & > std::minmax ( const _Tp & __a,
const _Tp & __b )
inlinenodiscardconstexpr

Determines min and max at once as an ordered pair.

Parameters
__aA thing of arbitrary type.
__bAnother thing of arbitrary type.
Returns
A pair(__b, __a) if __b is smaller than __a, pair(__a, __b) otherwise.

Definition at line 3299 of file stl_algo.h.

◆ minmax() [2/2]

template<typename _Tp, typename _Compare>
pair< const _Tp &, const _Tp & > std::minmax ( const _Tp & __a,
const _Tp & __b,
_Compare __comp )
inlinenodiscardconstexpr

Determines min and max at once as an ordered pair.

Parameters
__aA thing of arbitrary type.
__bAnother thing of arbitrary type.
__compA comparison functor .
Returns
A pair(__b, __a) if __b is smaller than __a, pair(__a, __b) otherwise.

Definition at line 3320 of file stl_algo.h.

◆ minmax_element() [1/2]

template<typename _ForwardIterator>
pair< _ForwardIterator, _ForwardIterator > std::minmax_element ( _ForwardIterator __first,
_ForwardIterator __last )
inlinenodiscardconstexpr

Return a pair of iterators pointing to the minimum and maximum elements in a range.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
make_pair(m, M), where m is the first iterator i in [__first, __last) such that no other element in the range is smaller, and where M is the last iterator i in [__first, __last) such that no other element in the range is larger.

Definition at line 3400 of file stl_algo.h.

◆ minmax_element() [2/2]

template<typename _ForwardIterator, typename _Compare>
pair< _ForwardIterator, _ForwardIterator > std::minmax_element ( _ForwardIterator __first,
_ForwardIterator __last,
_Compare __comp )
inlinenodiscardconstexpr

Return a pair of iterators pointing to the minimum and maximum elements in a range.

Parameters
__firstStart of range.
__lastEnd of range.
__compComparison functor.
Returns
make_pair(m, M), where m is the first iterator i in [__first, __last) such that no other element in the range is smaller, and where M is the last iterator i in [__first, __last) such that no other element in the range is larger.

Definition at line 3428 of file stl_algo.h.

◆ next_permutation() [1/2]

template<typename _BidirectionalIterator>
bool std::next_permutation ( _BidirectionalIterator __first,
_BidirectionalIterator __last )
inlineconstexpr

Permute range into the next dictionary ordering.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
False if wrapped to first permutation, true otherwise.

Treats all permutations of the range as a set of dictionary sorted sequences. Permutes the current sequence into the next one of this set. Returns true if there are more sequences to generate. If the sequence is the largest of the set, the smallest is generated and false returned.

Definition at line 2950 of file stl_algo.h.

◆ next_permutation() [2/2]

template<typename _BidirectionalIterator, typename _Compare>
bool std::next_permutation ( _BidirectionalIterator __first,
_BidirectionalIterator __last,
_Compare __comp )
inlineconstexpr

Permute range into the next dictionary ordering using comparison functor.

Parameters
__firstStart of range.
__lastEnd of range.
__compA comparison functor.
Returns
False if wrapped to first permutation, true otherwise.

Treats all permutations of the range [__first,__last) as a set of dictionary sorted sequences ordered by __comp. Permutes the current sequence into the next one of this set. Returns true if there are more sequences to generate. If the sequence is the largest of the set, the smallest is generated and false returned.

Definition at line 2983 of file stl_algo.h.

◆ nth_element() [1/2]

template<typename _RandomAccessIterator>
void std::nth_element ( _RandomAccessIterator __first,
_RandomAccessIterator __nth,
_RandomAccessIterator __last )
inlineconstexpr

Sort a sequence just enough to find a particular position.

Parameters
__firstAn iterator.
__nthAnother iterator.
__lastAnother iterator.
Returns
Nothing.

Rearranges the elements in the range [__first, __last) so that *__nth is the same element that would have been in that position had the whole sequence been sorted. The elements either side of *__nth are not completely sorted, but for any iterator i in the range [__first, __nth) and any iterator j in the range [__nth, __last) it holds that *j < *i is false.

Definition at line 4753 of file stl_algo.h.

References __lg().

◆ nth_element() [2/2]

template<typename _RandomAccessIterator, typename _Compare>
void std::nth_element ( _RandomAccessIterator __first,
_RandomAccessIterator __nth,
_RandomAccessIterator __last,
_Compare __comp )
inlineconstexpr

Sort a sequence just enough to find a particular position using a predicate for comparison.

Parameters
__firstAn iterator.
__nthAnother iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
Nothing.

Rearranges the elements in the range [__first, __last) so that *__nth is the same element that would have been in that position had the whole sequence been sorted. The elements either side of *__nth are not completely sorted, but for any iterator i in the range [__first, __nth) and any iterator j in the range [__nth, __last) it holds that __comp(*j, *i) is false.

Definition at line 4793 of file stl_algo.h.

References __lg().

◆ partial_sort() [1/2]

template<typename _RandomAccessIterator>
void std::partial_sort ( _RandomAccessIterator __first,
_RandomAccessIterator __middle,
_RandomAccessIterator __last )
inlineconstexpr

Sort the smallest elements of a sequence.

Parameters
__firstAn iterator.
__middleAnother iterator.
__lastAnother iterator.
Returns
Nothing.

Sorts the smallest (__middle - __first) elements in the range [first, last) and moves them to the range [__first, __middle). The order of the remaining elements in the range [__middle, __last) is unspecified. After the sort if i and j are iterators in the range [__first, __middle) such that i precedes j and k is an iterator in the range [__middle, __last) then *j < *i and *k < *i are both false.

Definition at line 4677 of file stl_algo.h.

◆ partial_sort() [2/2]

template<typename _RandomAccessIterator, typename _Compare>
void std::partial_sort ( _RandomAccessIterator __first,
_RandomAccessIterator __middle,
_RandomAccessIterator __last,
_Compare __comp )
inlineconstexpr

Sort the smallest elements of a sequence using a predicate for comparison.

Parameters
__firstAn iterator.
__middleAnother iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
Nothing.

Sorts the smallest (__middle - __first) elements in the range [__first, __last) and moves them to the range [__first, __middle). The order of the remaining elements in the range [__middle, __last) is unspecified. After the sort if i and j are iterators in the range [__first, __middle) such that i precedes j and k is an iterator in the range [__middle, __last) then *__comp(j, *i) and __comp(*k, *i) are both false.

Definition at line 4716 of file stl_algo.h.

◆ partial_sort_copy() [1/2]

template<typename _InputIterator, typename _RandomAccessIterator>
_RandomAccessIterator std::partial_sort_copy ( _InputIterator __first,
_InputIterator __last,
_RandomAccessIterator __result_first,
_RandomAccessIterator __result_last )
inlineconstexpr

Copy the smallest elements of a sequence.

Parameters
__firstAn iterator.
__lastAnother iterator.
__result_firstA random-access iterator.
__result_lastAnother random-access iterator.
Returns
An iterator indicating the end of the resulting sequence.

Copies and sorts the smallest N values from the range [__first, __last) to the range beginning at __result_first, where the number of elements to be copied, N, is the smaller of (__last - __first) and (__result_last - __result_first). After the sort if i and j are iterators in the range [__result_first,__result_first + N) such that i precedes j then *j < *i is false. The value returned is __result_first + N.

Definition at line 1662 of file stl_algo.h.

◆ partial_sort_copy() [2/2]

template<typename _InputIterator, typename _RandomAccessIterator, typename _Compare>
_RandomAccessIterator std::partial_sort_copy ( _InputIterator __first,
_InputIterator __last,
_RandomAccessIterator __result_first,
_RandomAccessIterator __result_last,
_Compare __comp )
inlineconstexpr

Copy the smallest elements of a sequence using a predicate for comparison.

Parameters
__firstAn input iterator.
__lastAnother input iterator.
__result_firstA random-access iterator.
__result_lastAnother random-access iterator.
__compA comparison functor.
Returns
An iterator indicating the end of the resulting sequence.

Copies and sorts the smallest N values from the range [__first, __last) to the range beginning at result_first, where the number of elements to be copied, N, is the smaller of (__last - __first) and (__result_last - __result_first). After the sort if i and j are iterators in the range [__result_first, __result_first + N) such that i precedes j then __comp(*j, *i) is false. The value returned is __result_first + N.

Definition at line 1713 of file stl_algo.h.

◆ prev_permutation() [1/2]

template<typename _BidirectionalIterator>
bool std::prev_permutation ( _BidirectionalIterator __first,
_BidirectionalIterator __last )
inlineconstexpr

Permute range into the previous dictionary ordering.

Parameters
__firstStart of range.
__lastEnd of range.
Returns
False if wrapped to last permutation, true otherwise.

Treats all permutations of the range as a set of dictionary sorted sequences. Permutes the current sequence into the previous one of this set. Returns true if there are more sequences to generate. If the sequence is the smallest of the set, the largest is generated and false returned.

Definition at line 3053 of file stl_algo.h.

◆ prev_permutation() [2/2]

template<typename _BidirectionalIterator, typename _Compare>
bool std::prev_permutation ( _BidirectionalIterator __first,
_BidirectionalIterator __last,
_Compare __comp )
inlineconstexpr

Permute range into the previous dictionary ordering using comparison functor.

Parameters
__firstStart of range.
__lastEnd of range.
__compA comparison functor.
Returns
False if wrapped to last permutation, true otherwise.

Treats all permutations of the range [__first,__last) as a set of dictionary sorted sequences ordered by __comp. Permutes the current sequence into the previous one of this set. Returns true if there are more sequences to generate. If the sequence is the smallest of the set, the largest is generated and false returned.

Definition at line 3086 of file stl_algo.h.

◆ sort() [1/2]

template<typename _RandomAccessIterator>
void std::sort ( _RandomAccessIterator __first,
_RandomAccessIterator __last )
inlineconstexpr

Sort the elements of a sequence.

Parameters
__firstAn iterator.
__lastAnother iterator.
Returns
Nothing.

Sorts the elements in the range [__first, __last) in ascending order, such that for each iterator i in the range [__first, __last - 1), *(i+1) < *i is false.

The relative ordering of equivalent elements is not preserved, use stable_sort() if this is needed.

Definition at line 4831 of file stl_algo.h.

◆ sort() [2/2]

template<typename _RandomAccessIterator, typename _Compare>
void std::sort ( _RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare __comp )
inlineconstexpr

Sort the elements of a sequence using a predicate for comparison.

Parameters
__firstAn iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
Nothing.

Sorts the elements in the range [__first, __last) in ascending order, such that __comp(*(i+1), *i) is false for every iterator i in the range [__first, __last - 1).

The relative ordering of equivalent elements is not preserved, use stable_sort() if this is needed.

Definition at line 4862 of file stl_algo.h.

◆ stable_sort() [1/2]

template<typename _RandomAccessIterator>
void std::stable_sort ( _RandomAccessIterator __first,
_RandomAccessIterator __last )
inline

Sort the elements of a sequence, preserving the relative order of equivalent elements.

Parameters
__firstAn iterator.
__lastAnother iterator.
Returns
Nothing.

Sorts the elements in the range [__first,__last) in ascending order, such that for each iterator i in the range [__first,__last-1), *(i+1)<*i is false.

The relative ordering of equivalent elements is preserved, so any two elements x and y in the range [__first,__last) such that x<y is false and y<x is false will have the same relative ordering after calling stable_sort().

Definition at line 5061 of file stl_algo.h.

◆ stable_sort() [2/2]

template<typename _RandomAccessIterator, typename _Compare>
void std::stable_sort ( _RandomAccessIterator __first,
_RandomAccessIterator __last,
_Compare __comp )
inline

Sort the elements of a sequence using a predicate for comparison, preserving the relative order of equivalent elements.

Parameters
__firstAn iterator.
__lastAnother iterator.
__compA comparison functor.
Returns
Nothing.

Sorts the elements in the range [__first,__last) in ascending order, such that for each iterator i in the range [__first,__last-1), __comp(*(i+1),*i) is false.

The relative ordering of equivalent elements is preserved, so any two elements x and y in the range [__first,__last) such that __comp(x,y) is false and __comp(y,x) is false will have the same relative ordering after calling stable_sort().

Definition at line 5096 of file stl_algo.h.