Listing C++ STL Algorithms
February 16, 2020
Recently, I came across a YouTube video on 105 C++ STL algorithms. This made me realise how little I knew about the C++ STL, and that I should study it in greater detail to become a more effective C++ programmer.
Hence, I’ve decided to pen down my notes on the C++ STL here, starting with a list of algorithms and their categories in the C++ STL.
Credits to the YouTube video linked above and the speaker’s website.
Prelude: learning points
- Use STL algorithms to make your code more expressive (replace for-loops with the right algorithm)
- Understand the pre/post-requisites, time complexities, and implementations of the algorithms
- Understand what abstractions work well and complement the library with your own algorithms
- Use https://cppreference.com to read the documentation for each algorithm
Permutations
Heaps
- make_heap
- push_heap
- pop_heap
- sort_heap
- is_heap
- is_heap_until
Sorting
- sort
- stable_sort
- partial_sort
- partial_sort_copy
- nth_element
- sort_heap
- inplace_merge
- is_sorted
- is_sorted_until
Partitioning
- partition
- partition_copy
- stable_partition
- partition_point
- is_partition
- is_partitioned_until
Other permutations
- rotate
- rotate_copy
- shuffle
- next_permutation
- prev_permutation
- reverse
- reverse_copy
Modifiers
- stable_sort, stable_partition (stable_*)
- is_sorted, is_partitioned, is_heap (is_*)
- is_sorted_until, is_partitioned_until, is_heap_until (is_*_until)
Queries
Numerics
- count
- count_if
- accumulate
- transform_reduce
- reduce
- partial_sum
- inclusive_scan
- exclusive_scan
- transform_inclusive_scan
- transform_exclusive_scan
- inner_product
- adjacent_difference
- sample
Properties on 1 range
- all_of
- any_of
- none_of
Properties on 2 ranges
- equal
- is_permutation
- lexicographical_compare
- mismatch
Searching for a value in an unsorted range
- find
- find_if
- find_if_not
- adjacent_find
Searching for a value in a sorted range
- equal_range
- lower_bound
- upper_bound
- binary_search
Searching for a range within a range
- search
- search_n
- find_end
- find_first_of
Searching for a relative value in range
- max_element
- min_element
- minmax_element
Sets
- set_difference
- set_intersection
- set_union
- set_symmetric_difference
- includes
- merge
Moving elements
- copy
- copy_n
- copy_if
- copy_backward
- uninitialized_fill
- move
- uninitialized_move
- move_backward
- swap_ranges
Modifying values
- fill
- fill_n
- uninitialized_fill
- generate
- generate_n
- iota
- replace
- replace_if
- replace_copy
- replacecopyif
Changing structures
- remove
- remove_if
- remove_copy
- remove_copy_if
- erase
- unique
- unique_copy
Raw memory
- uninitialized_fill
- uninitialized_fill_n
- uninitialized_copy
- uninitialized_copy_n
- uninitialized_move
- uninitialized_move_n
- destroy
- destroy_n
- uninitialized_default_construct
- uninitialized_default_construct_n
- uninitialized_value_construct
- uninitialized_value_construct_n
Others
- transform
- for_each (This is meant for side-effects. Anything else is more appropriately expressed by other algorithms)
- for_each_n
Boost library
- gather
- sort_subrange
- is_palindrome
- boyer_moore
- one_of
- …and more!