std::inplace_vector<T,N>:: resize
From cppreference.net
<
cpp
|
container
|
inplace vector
|
constexpr
void
resize
(
size_type count
)
;
|
(1) | (C++26부터) |
|
constexpr
void
resize
(
size_type count,
const
value_type
&
value
)
;
|
(2) | (C++26부터) |
컨테이너의 크기를 count 개의 요소를 포함하도록 조정합니다:
- count 가 현재 크기와 같으면 아무 작업도 수행하지 않습니다.
- 현재 크기가 count 보다 크면, 컨테이너는 처음 count 개의 요소로 축소됩니다.
- 현재 크기가 count 보다 작으면:
1)
추가적인
default-inserted
요소들이 추가됩니다.
2)
value
의 추가 복사본이 추가됩니다.
목차 |
매개변수
| count | - | 컨테이너의 새로운 크기 |
| value | - | 새로운 요소들을 초기화할 값 |
| 타입 요구사항 | ||
|
-
|
||
복잡도
현재 크기와 count 사이의 차이에 선형적으로 비례합니다.
예외
어떤 이유로든 예외가 발생하면, 이 함수들은 아무런 효과를 가지지 않습니다( strong exception safety guarantee ).
예제
이 코드 실행
#include <inplace_vector> #include <print> int main() { std::inplace_vector<int, 6> v(6, 9); std::println("Initially, v = {}", v); v.resize(2); std::println("After resize(2), v = {}", v); v.resize(4); std::println("After resize(4), v = {}", v); v.resize(6, -1); std::println("After resize(6, -1), v = {}", v); try { std::print("Trying resize(13): "); v.resize(13); // throws, because count > N; v is left unchanged } catch(const std::bad_alloc& ex) { std::println("ex.what(): {}", ex.what()); } std::println("After exception, v = {}", v); }
가능한 출력:
Initially, v = [9, 9, 9, 9, 9, 9] After resize(2), v = [9, 9] After resize(4), v = [9, 9, 0, 0] After resize(6, -1), v = [9, 9, 0, 0, -1, -1] Trying resize(13): ex.what(): std::bad_alloc After exception, v = [9, 9, 0, 0, -1, -1]
참고 항목
|
[static]
|
가능한 최대 원소 개수를 반환합니다
(public static member function) |
|
원소 개수를 반환합니다
(public member function) |
|
|
[static]
|
현재 할당된 저장 공간에 보관할 수 있는 원소 개수를 반환합니다
(public static member function) |
|
컨테이너가 비어 있는지 확인합니다
(public member function) |