std::generate in C++ Last Updated : 21 Jul, 2017 Comments Improve Suggest changes Like Article Like Report std::generate, as the name suggests is an STL algorithm, which is used to generate numbers based upon a generator function, and then, it assigns those values to the elements in the container in the range [first, last). The generator function has to be defined by the user, and it is called successively for assigning the numbers. Template function: void generate (ForwardIterator first, ForwardIterator last, Generator gen); first: Forward iterator pointing to the first element of the container. last: Forward iterator pointing to the last element of the container. gen: A generator function, based upon which values will be assigned. Returns: none Since, it has a void return type, so it does not return any value. CPP // C++ program to demonstrate the use of std::generate #include <iostream> #include <vector> #include <algorithm> // Defining the generator function int gen() { static int i = 0; return ++i; } using namespace std; int main() { int i; // Declaring a vector of size 10 vector<int> v1(10); // using std::generate std::generate(v1.begin(), v1.end(), gen); vector<int>::iterator i1; for (i1 = v1.begin(); i1 != v1.end(); ++i1) { cout << *i1 << " "; } return 0; } Output: 1 2 3 4 5 6 7 8 9 10 Next: std::generate_n in C++ Comment More infoAdvertise with us Next Article std::generate in C++ M Mrigendra Singh Improve Article Tags : Misc C++ STL cpp-algorithm-library Practice Tags : CPPMiscSTL Similar Reads std::generate_n in C++ std::generate is an STL algorithm, which is used to generate numbers based upon a generator function, and then, it assigns those values to the elements in the container in the range [first, last). The generator function has to be defined by the user, and it is called successively for assigning the n 2 min read std::function in C++ The std::function() in C++ is a function wrapper class which can store and call any function or a callable object. In this article, we will learn about std::function in C++ and how to use it in different cases.Table of ContentWhat is std::function in C++?Example of std::functionMember Functions of s 5 min read random header in C++ | Set 1(Generators) This header introduces random number generation facilities. This library allows to produce random numbers using combinations of generators and distributions. Generators: Objects that generate uniformly distributed numbers.Distributions: Objects that transform sequences of numbers generated by a gene 11 min read make_pair() in C++ STL In C++, make_pair() is a standard library function used to construct a key-value pair from the given arguments. The type of the pair constructed is deduced automatically from the type of arguments. In this article, we will learn about make_pair() function in C++.Letâs take a quick look at a simple e 3 min read #define in C++ In C++, #define is a preprocessor directive used to define a macro. Macros are a way to represent a fragment of code or a constant value by giving it a name. When the preprocessor encounters the macro name in the code, it replaces it with the corresponding code fragment or value that is defined usin 4 min read Like