std::forward_list<T,Allocator>::sort (3) - Linux Manuals
std::forward_list<T,Allocator>::sort: std::forward_list<T,Allocator>::sort
NAME
std::forward_list<T,Allocator>::sort - std::forward_list<T,Allocator>::sort
Synopsis
void sort(); (1) (since C++11)
template< class Compare > (2) (since C++11)
void sort( Compare comp );
Sorts the elements in ascending order. The order of equal elements is preserved. The first version uses operator< to compare the elements, the second version uses the given comparison function comp.
If an exception is thrown, the order of elements in *this is unspecified.
Parameters
comp - While the signature does not need to have const &, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value_category (thus, Type1 & is not allowed
Return value
(none)
Complexity
Approximately N log N comparisons, where N is the number of elements in the list.
Notes
std::sort requires random access iterators and so cannot be used with forward_list. This function also differs from std::sort in that it does not require the element type of the forward_list to be swappable, preserves the values of all iterators, and performs a stable sort.
Example
// Run this code
Output: