Namespaces
Variants

std::inplace_vector<T,N>:: reserve

From 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)
사용되지 않는 메모리를 해제하여 메모리 사용량을 줄입니다
(public static member function)