C++: Difference between revisions

564 bytes added ,  9 March 2020
Line 293: Line 293:
====std::find====
====std::find====
[https://en.cppreference.com/w/cpp/algorithm/find Reference]<br>
[https://en.cppreference.com/w/cpp/algorithm/find Reference]<br>
====std::generate===
Allows you to fill a container using a function call<br>
<syntaxhighlight lang="cpp">
#include <random>
#include <iostream>
#include <algorithm>
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    # Fill with integers in [0, 10]
    std::uniform_int_distribution<> dis(0, 10);
    std::vector<int> my_vec(10, 0);
    std::generate(my_vec.begin(), my_vec.end(), [&](){return dis(gen);});
   
    for (int v : my_vec) {
        std::cout << v << " ";
    }
    std::cout << std::endl;
    return 0;
}
</syntaxhighlight>


===Numeric===
===Numeric===