public member function
<array>

std::array::fill

void fill (const value_type& val);
Fill array with value
Sets val as the value for all the elements in the array object.

Parameters

val
Value to fill the array with.
Member type value_type is the type of the elements in the container, defined in array as an alias of its first template parameter (T).

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// array::fill example
#include <iostream>
#include <array>

int main () {
  std::array<int,6> myarray;

  myarray.fill(5);

  std::cout << "myarray contains:";
  for ( int& x : myarray) { std::cout << ' ' << x; }

  std::cout << '\n';

  return 0;
}

Output:
myarray contains: 5 5 5 5 5 5


Complexity

Linear: Performs as many assignment operations as the size of the array object.

Iterator validity

No changes.

Data races

All contained elements are modified.

Exception safety

Basic guarantee: if an exception is thrown, the container is in a valid state.
It throws if the assignment of any element throws.

See also