set_union is useful to find an union of two sorted vectors, where result is also sorted:
set_union(first.begin(), first.end(),
second.begin(), second.end(),
result.begin());
The push_back is called whenever the iterator is assigned to. It is really useful using it with other STL algorithms.
std::optional contains a value or not. It can be used with if:
if (auto value = get_optional_value()) {
std::cout << *value;
}
nulloptused for the absent value.value_oris useful for getting the value or the specified value.
list::spliceconcatenates two lists inO(1)time, without any copying of data.list::insertinserts elements by copying elements inO(n)time.
std::random_devicecan be used to seed a random number generator.- or a time.
std::mt19937- is a pseudo-random generator of 32-bit numbers.std::uniform_int_distribution<int>- uniform discrete distribution. An instance ofstd::mt19937must passed.
std::random_device rd();
std::mt19937 rng(rd());
std::sample(in.begin(), in.end(), std::back_inserter(out), 5, rng);