A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/array/array/fill/ below:

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 safetyBasic guarantee: if an exception is thrown, the container is in a valid state.
It throws if the assignment of any element throws.

See also
array::data
Get pointer to data (public member function)
fill
Fill range with value (function template)
fill_n
Fill sequence with value (function template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4