std::array<T,N>:: fill
From cppreference.net
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::array
| Member types | ||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||
| Deduction guides (C++17) | ||||||||||||||||||||||||||
|
void
fill
(
const
T
&
value
)
;
|
(C++11부터)
(C++20부터 constexpr) |
|
컨테이너 내의 모든 요소에 value 를 할당합니다.
목차 |
매개변수
| value | - | 요소에 할당할 값 |
반환값
(없음)
복잡도
컨테이너 크기에 선형적으로 비례합니다.
예제
이 코드 실행
#include <array> #include <cstddef> #include <iostream> int main() { constexpr std::size_t xy = 4; using Cell = std::array<unsigned char, 8>; std::array<Cell, xy * xy> board; board.fill({0xE2, 0x96, 0x84, 0xE2, 0x96, 0x80, 0, 0}); // "▄▀"; for (std::size_t count{}; Cell c : board) std::cout << c.data() << ((++count % xy) ? "" : "\n"); }
가능한 출력:
▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀ ▄▀▄▀▄▀▄▀
참고 항목
|
주어진 범위의 모든 요소에 지정된 값을 복사 할당합니다
(function template) |
|
|
주어진 범위의 N개 요소에 지정된 값을 복사 할당합니다
(function template) |
|
|
(C++20)
|
요소 범위에 특정 값을 할당합니다
(algorithm function object) |