Sets val as the value for all the elements in the array object.
引數
val
Value to fill the array with. 成員型別value_typeis the type of the elements in the container, defined in array as an alias of its first template parameter (T).
返回值
無
示例
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;
}
輸出
myarray contains: 5 5 5 5 5 5
複雜度
Linear: Performs as many assignment operations as the size of the array object.
迭代器有效性
沒有變化。
資料競爭
所有包含的元素都被修改。
異常安全
Basic guarantee: if an exception is thrown, the container is in a valid state. It throws if the assignment of any element throws.