fill


Set every item in a range to a particular value.

Assign value to each element in the range [ first ... last ). Return an iterator equal to result + n where n = last - first .

Library

Standards<ToolKit>

Declaration


#include <algorithm>

template< class ForwardIterator, class T >
void fill
  (
  ForwardIterator first,
  ForwardIterator last,
  const T& value
  );
  

Complexity

Time complexity is linear as ( last - first ) assignments are performed. Space complexity is constant.

Example <ospace/osstd/examples/fill1.cpp>
#include <iostream>
#include <algorithm>
#include <vector>

void
main()
  {
  vector< int > v( 10 );

  fill( v.begin(), v.end(), 42 );

  for ( int i = 0; i < 10; ++i )
    cout << v[ i ] << ` `;
  cout << "\n";
  }
42 42 42 42 42 42 42 42 42 42

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.