Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

 

History

History
25 lines (20 loc) · 673 Bytes

generate.md

File metadata and controls

25 lines (20 loc) · 673 Bytes

generate

Description : 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.

Example:

    int gen() { 
        static int i = 0; 
        return ++i; 
    } 
  
    int main() { 
        int i; 
        std::vector<int> v1(10); 
  
        std::generate(v1.begin(), v1.end(), gen); 
  
        for (auto value : v1) {
            std::cout << value << " ";
        }

        return 0; 
    } 

Run Code