Many great functions offered by the C++ standard library go criminally underused. I've listed a few of my favorites here.
C++11
- std::iota fills a data structure with incrementing values.
C++17
- std::unique iterates through a sorted data structure and puts adjacent duplicate values at the end of the structure.
- std::count counts values in a data structure that compare equal to an argument.
- std::set_intersection finds the common elements in 2 sorted data structures.
C++20
- std::clamp takes 3 arguments and "clamps" the 2nd argument into the range of the 1st and 3rd.
- std::partial_sum prefix sums a data structure.
- std::accumulate sums up the values of a data structure.
- std::adjacent_difference creates a difference array.
- <bit> has various functions for easier bitwise manipulation. Featuring std::popcount.
- std::midpoint averages 2 arguments, rounding towards the first.
C++23 (Not supported by Codeforces)
- std::unreachable marks unreachable code to enable compiler optimization and debug trapping. (Pre-C++23 alternatives: GCC/Clang:
__builtin_unreachable()
MSVC:__assume(false)
)
Miscellaneous
If I missed anything, comment it and I'll add it.