std::inplace_vector<T,N>::reserve
cppreference.net에서
static constexpr void reserve( size_type new_cap );
|
(C++26부터) | |
아무 작업도 수행하지 않습니다. 단, std::bad_alloc을 던질 수 있습니다. 용량(즉, 내부 저장소 크기)을 늘리라는 요청은 무시됩니다. std::inplace_vector<T, N>은(는) 고정 용량 컨테이너이기 때문입니다.
매개변수
| new_cap | - |
inplace_vector
의 새로운 용량, 요소 개수 단위
|
복잡도
상수.
예외
std::bad_alloc 만약 new_cap > capacity ( ) 가 true 인 경우.
참고 사항
이 함수는 벡터와 유사한 인터페이스와의 호환성을 위해 존재합니다.
예제
이 코드 실행
#include <cassert> #include <inplace_vector> #include <iostream> int main() { std::inplace_vector<int, 4> v{1, 2, 3}; assert(v.capacity() == 4 && v.size() == 3); v.reserve(2); // 아무 작업도 수행하지 않음 assert(v.capacity() == 4 && v.size() == 3); try { v.reserve(13); // 예외 발생, 요청된 용량이 N보다 큼; v는 변경되지 않음 } catch(const std::bad_alloc& ex) { std::cout << ex.what() << '\n'; } assert(v.capacity() == 4 && v.size() == 3); }
가능한 출력:
std::bad_alloc
참고 항목
|
요소의 개수를 반환합니다
(public member function) |
|
|
[static]
|
가능한 최대 요소 개수를 반환합니다
(public static member function) |
|
저장된 요소의 개수를 변경합니다
(public member function) |
|
|
[static]
|
현재 할당된 저장 공간에 보관할 수 있는 요소의 개수를 반환합니다
(public static member function) |
|
[static]
|
사용되지 않는 메모리를 해제하여 메모리 사용량을 줄입니다
(public static member function) |