I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com

fill

Replaces each element with a given value
+ View version details

Key Facts

Gyroscopic Couple: The rate of change of angular momentum (\inline \tau) = \inline I\omega\Omega (In the limit).
  • \inline I = Moment of Inertia.
  • \inline \omega = Angular velocity
  • \inline \Omega = Angular velocity of precession.


Blaise Pascal (1623-1662) was a French mathematician, physicist, inventor, writer and Catholic philosopher.

Leonhard Euler (1707-1783) was a pioneering Swiss mathematician and physicist.

Definition

The fill() algorithm is defined in the standard header <algorithm> and in the nonstandard backward-compatibility header <algo.h>.

Interface

#include <algorithm>
template < class ForwardIterator, class Type >
   void fill(
      ForwardIterator first, 
      ForwardIterator last, 
      const Type& val
   );

Parameters:
Parameter Description
first A forward iterator addressing the position of the first element in the range to be traversed
last A forward iterator addressing the position one past the final element in the range to be traversed
val The value to be assigned to elements in the range [first, last)

Description

Fill algorithm fi lls a range with a given value by using operator=.

Return Value

None.

Complexity

The complexity is linear; performs (last - first) assignments.
Example:
Example - fill function
Problem
The following program demonstrates how to use fill() function.
Workings
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
 
int main()
{
  vector <int> vec;
  vector <int>::iterator Iter1;
  int i;
  for (i = 10; i <= 20; i++)
    vec.push_back(i);
  cout <<"Vector vec data: ";
  for(Iter1 = vec.begin(); Iter1 != vec.end(); Iter1++)
    cout <<*Iter1<<" ";
  cout <<endl;
  // fill the last 4 positions with a value of 9
  cout <<"\nOperation: fill(vec.begin() + 4, vec.end(), 9)\n";
  fill(vec.begin() + 4, vec.end(), 9);
  cout <<"Modified vec data: ";
  for (Iter1 = vec.begin(); Iter1 != vec.end(); Iter1++)
    cout <<*Iter1<<" ";
  cout <<endl;
 
  return 0;
}
Solution
Output:

Vector vec data: 10 11 12 13 14 15 16 17 18 19 20
Operation: fill(vec.begin() + 4, vec.end(), 9)
Modified vec data: 10 11 12 13 9 9 9 9 9 9 9
References