Make the most out of the C++ STL
Difference between en1 and en2, changed 554 character(s)
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](https://en.cppreference.com/w/cpp/algorithm/iota) fills a data structure with incrementing values.↵

### C++17↵
- [std::unique](https://en.cppreference.com/w/cpp/algorithm/unique) iterates through a sorted data structure and puts adjacent duplicate values at the end of the structure.↵
- [std::count](https://en.cppreference.com/w/cpp/algorithm/count) counts values in a data structure that compare equal to an argument.↵
- [std::set_intersection](https://en.cppreference.com/w/cpp/algorithm/set_intersection) finds the common elements in 2 sorted data structures.↵
- [std::rotate](https://en.cppreference.com/w/cpp/algorithm/rotate) shifts elements, placing the rightmost elements at the beginning as necessary.↵

### C++20↵
- [std::clamp](https://en.cppreference.com/w/cpp/algorithm/clamp) takes 3 
argumentvalues and "clamps" the 2nd argument into the range ofbounds set by the 1st and 3rd.↵
- [std::partial_sum](https://en.cppreference.com/w/cpp/algorithm/partial_sum) prefix sums a data structure.↵
- [std::accumulate](https://en.cppreference.com/w/cpp/algorithm/accumulate) sums up the values of a data structure.↵
- [std::adjacent_difference](https://en.cppreference.com/w/cpp/algorithm/adjacent_difference) creates a difference array.↵
- [\<bit\>](https://en.cppreference.com/w/cpp/header/bit) has various functions for easier bitwise manipulation. Featuring std::popcount.↵
- [std::midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) averages 2 arguments, rounding towards the first.↵

### C++23 (Not supported by Codeforces)↵
- [std::unreachable](https://en.cppreference.com/w/cpp/utility/unreachable) marks unreachable code to enable compiler optimization and debug trapping. (Pre-C++23 alternatives: GCC/Clang: `__builtin_unreachable()` MSVC: `__assume(false)`)↵

### Miscellaneous↵
- [std::max](https://en.cppreference.com/w/cpp/algorithm/max) and [std::min](https://en.cppreference.com/w/cpp/algorithm/min) take an initializer list, so you don't have to nest them within themselves.↵

If I missed anything, comment it and I'll add it
- Binary search on a monotonic function using std::partition_point and std::views::iota: [See here](https://codeforces.net/blog/entry/123166?#comment-1092212)↵

If I missed anything, comment it and I'll add it.↵
I understand some of these functions are categorized in the wrong C++ version, but I can't figure out what the right one is for the ones that have been pointed out, such as partial_sum, accumulate, and adjacent_difference
.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English snowmanonahoe 2023-12-12 00:50:27 554 Add content based on comments. Thanks to AlphaMale06, Boboge, cosenza, drdilyor.
en1 English snowmanonahoe 2023-12-09 22:17:11 2077 Initial revision (published)