function template
<algorithm>

# std::fill

```template <class ForwardIterator, class T>
void fill (ForwardIterator first, ForwardIterator last, const T& val);```
Fill range with value
Assigns val to all the elements in the range `[first,last)`.

The behavior of this function template is equivalent to:
 ``12345678`` ``````template void fill (ForwardIterator first, ForwardIterator last, const T& val) { while (first != last) { *first = val; ++first; } }``````

### Parameters

first, last
Forward iterators to the initial and final positions in a sequence of elements that support being assigned a value of type T. The range filled is `[first,last)`, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
val
Value to assign to the elements in the filled range.

none

### Example

 ``123456789101112131415161718`` ``````// fill algorithm example #include // std::cout #include // std::fill #include // std::vector int main () { std::vector myvector (8); // myvector: 0 0 0 0 0 0 0 0 std::fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0 std::fill (myvector.begin()+3,myvector.end()-2,8); // myvector: 5 5 5 8 8 8 0 0 std::cout << "myvector contains:"; for (std::vector::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0; }``````

Output:
 ```myvector contains: 5 5 5 8 8 8 0 0 ```

### Complexity

Linear in the distance between first and last: Assigns a value to each element.

### Data races

The objects in the range `[first,last)` are modified (each object is accessed exactly once).

### Exceptions

Throws if either an element assignment or an operation on an iterator throws.
Note that invalid arguments cause undefined behavior.