STL algorithm header
#include <algorithm>
max(), min()
template<typename T>
const T& max(const T& a, const T& b);
max_element(), min_element()
template<typename ForwardIt>
ForwardIterator max_element(ForwardIt first, ForwardIt last);
swap()
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a = 3, b = 5;
swap(a, b); // void swap(T& a, T& b);
}
swap_ranges()
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a[5] = {1, 2, 3, 4, 5};
int b[5] = {6, 7, 8, 9, 0};
swap_ranges(a, a + 3, b); // swap the elements from a[0] ~ a[2] to b[0] ~ b[2] (implicitly)
// very very very very very very very very very very very very very very very very very very very very very very very very long comment
}
copy()
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a[5] = {1, 2, 3, 4, 5};
int b[5] = {6, 7, 8, 9, 0};
copy(a + 1, a + 4, b + 1); // copy a[1] ~ a[3] to b[1] ~ b[3]
}
fill()
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a[5] = {1, 2, 3, 4, 5};
int b[5] = {6, 7, 8, 9, 0};
fill(a + 2, a + 5, 0); // fill a[2] ~ a[4] with 0
fill(b, b + 4, 3); // fill b[0] ~ b[3] with 3
}