|
|
|
|
|
by raegis
1371 days ago
|
|
I think Jonathan Boccara's talk, "105 STL Algorithms in Less Than an Hour" ( https://www.youtube.com/watch?v=2olsGf6JIkU ), gives a nice overview of the <algorithm> library. Also, the examples on the reference pages (usually near the bottom) at cppreference.com are usually pretty good. For example: Here's how to create a pseudo random number generator using the Mersenne Twister engine. std::mt19937 e; // Mersenne Twister engine
std::uniform_int_distribution<int> u(0,99999); // uniform ints 0 to 99999, inclusive
auto rng = std::bind(u,e); // so rng() retuns the next random number
And filling a vector with random numbers could look like this: std::vector<int> nums(1000);
std::generate(nums.begin(), nums.end(), rng);
This last line can be written in C++20 more simply like this: std::ranges::generate(nums,rng);
|
|