The fill() Algorithm

The fill() Algorithm

The algorithm fill() is declared in as follows:

 void fill(ForwardIterator f, ForwardIterator l, const T&);

The arguments f and l mark the sequence’s beginning and end, respectively. fill() fills the elements in the sequence with the fixed value T. This algorithm is useful when you want to initialize or reinitialize a sequence with a fixed value. For example, to initialize a char array, use fill() as follows:

 #include char *p = new char[100];std::fill(p, p+100, ''); // zero all characters

This is similar to calling memset(p, 0, 100). Note however, that fill() respects object semantics, unlike memset(). Therefore, you can use it to reinitialize a sequence of objects as well:

 #include #include #include std::vector < std::string> vs(100); std::fill(vs.begin(), vs.end(), "greetings!"); 

The vector vs initially contains 100 empty strings. fill() assigns a new value: “greetings!” to all the strings in the vector.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several