Namespaces
Variants

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

From cppreference.net
constexpr inplace_vector ( ) noexcept ;
(1) (C++26부터)
constexpr explicit inplace_vector ( size_type count ) ;
(2) (C++26부터)
constexpr inplace_vector ( size_type count, const T & value ) ;
(3) (C++26부터)
template < class InputIt >
constexpr inplace_vector ( InputIt first, InputIt last ) ;
(4) (C++26부터)
template < container-compatible-range < T > R >
constexpr inplace_vector ( std:: from_range_t , R && rg ) ;
(5) (C++26부터)
constexpr inplace_vector ( const inplace_vector & other ) ;
(6) (C++26부터)
constexpr inplace_vector ( inplace_vector && other )
noexcept ( N == 0 || std:: is_nothrow_move_constructible_v < T > ) ;
(7) (C++26부터)
constexpr inplace_vector ( std:: initializer_list < T > init ) ;
(8) (C++26부터)

다양한 데이터 소스로부터 새로운 inplace_vector 를 생성합니다.

1) inplace_vector 를 생성하며, data ( ) == nullptr 이고 size ( ) == 0 이다.
2) inplace_vector count 개의 기본 생성된 요소들로 구성합니다.
3) inplace_vector count 개의 value 값으로 구성된 요소들로 생성합니다.
4) 범위 [ first , last ) 의 내용으로 inplace_vector 를 생성합니다.
5) 범위 rg 의 내용으로 inplace_vector 를 생성합니다.
6) 복사 생성자 . other 의 내용을 복사하여 inplace_vector 를 생성합니다.
생성자는 trivial copy constructor 입니다, 만약 N > 0 이고 std:: is_trivially_copy_constructible_v < T > 가 모두 true 인 경우.
7) move constructor . inplace_vector 의 내용을 other 에서 이동 시맨틱을 사용하여 생성합니다.
생성자는 trivial move constructor 입니다, 만약 N > 0 그리고 std:: is_trivially_move_constructible_v < T > 가 모두 true 인 경우에.
8) inplace_vector 를 초기화자 리스트 init 의 내용으로 생성합니다.

목차

매개변수

count - 컨테이너의 크기
value - 컨테이너 요소를 초기화할 값
first, last - 복사할 요소들의 소스 범위 를 정의하는 반복자 쌍
rg - 컨테이너 요소를 초기화할 값들의 범위
other - 컨테이너 요소를 초기화하는 데 사용할 소스 inplace_vector
init - 컨테이너 요소를 초기화할 초기화자 리스트
타입 요구사항
-
T 는 오버로드 (2,3)을 사용하기 위해 DefaultInsertable 요구사항을 충족해야 함

복잡도

1) 상수.
2,3) count 에 대해 선형적입니다.
4) std:: distance ( first, last ) 에 대해 선형 시간 복잡도를 가짐.
5) 선형 시간, std :: ranges:: distance ( rg ) .
6,7) other 의 크기에 선형적입니다.
8) 크기가 init 에 선형적으로 비례합니다.

예외

2,3) std::bad_alloc 을 던집니다, 만약 count > N 인 경우.
5) 다음의 경우 std::bad_alloc 을 발생시킵니다: std :: ranges:: size ( rg ) > N .
8) 다음의 경우 std::bad_alloc 을 throw합니다: init. size ( ) > N .

예제

#include <cassert>
#include <initializer_list>
#include <inplace_vector>
#include <new>
#include <print>
#include <ranges>
int main()
{
    std::inplace_vector<int, 4> v1; // 오버로드 (1)
    assert(v1.size() == 0 && v1.capacity() == 4);
    std::inplace_vector<int, 0> v2; // 오버로드 (1), N == 0이 허용됨
    assert(v2.size() == 0 && v2.capacity() == 0);
    std::inplace_vector<int, 5> v3(3); // 오버로드 (2)
    assert(v3.size() == 3 && v3.capacity() == 5);
    std::println("v3 = {}", v3);
    try
    {
        std::inplace_vector<int, 3> v(4); // 오버로드 (2), 예외 발생: count > N
    }
    catch(const std::bad_alloc& ex1)
    {
        std::println("ex1.what(): {}", ex1.what());
    }
    std::inplace_vector<int, 5> v4(3, 8); // 오버로드 (3)
    assert(v4.size() == 3 && v4.capacity() == 5);
    std::println("v4 = {}", v4);
    try
    {
        std::inplace_vector<int, 3> v(4, 2); // 오버로드 (3), 예외 발생: count > N
    }
    catch(const std::bad_alloc& ex2)
    {
        std::println("ex2.what(): {}", ex2.what());
    }
    const auto init = {1, 2, 3};
    std::inplace_vector<int, 4> v5(init.begin(), init.end()); // 오버로드 (4)
    assert(v5.size() == 3 && v5.capacity() == 4);
    std::println("v5 = {}", v5);
    std::inplace_vector<int, 4> v6(std::from_range, init); // 오버로드 (5)
    assert(v6.size() == 3 && v6.capacity() == 4);
    std::println("v6 = {}", v6);
    std::inplace_vector<int, 4> v7(v6); // 오버로드 (6)
    assert(v7.size() == 3 && v7.capacity() == 4);
    std::println("v7 = {}", v7);
    assert(v6.size() == 3);
    std::inplace_vector<int, 4> v8(std::move(v6)); // 오버로드 (7)
    // 이동 후 v6는 유효하지만 불확정 상태로 남아 있음에 유의하십시오.
    assert(v8.size() == 3 && v8.capacity() == 4);
    std::println("v8 = {}", v8);
    std::inplace_vector<int, 4> v9(init); // 오버로드 (8)
    assert(v9.size() == 3 && v9.capacity() == 4);
    std::println("v9 = {}", v9);
    try
    {
        std::inplace_vector<int, 2> v(init); // 오버로드 (8), 예외 발생: init.size() > N
    }
    catch(const std::bad_alloc& ex3)
    {
        std::println("ex3.what(): {}", ex3.what());
    }
}

가능한 출력:

v3 = [0, 0, 0]
ex1.what(): std::bad_alloc
v4 = [42, 42, 42]
ex2.what(): std::bad_alloc
v5 = [1, 2, 3]
v6 = [1, 2, 3]
v7 = [1, 2, 3]
v8 = [1, 2, 3]
v9 = [1, 2, 3]
ex3.what(): std::bad_alloc

참고 항목

컨테이너에 값을 할당합니다
(public member function)
[static]
현재 할당된 저장 공간에 보관할 수 있는 요소의 수를 반환합니다
(public static member function)
기본 연속 저장소에 대한 직접 접근
(public member function)
요소의 수를 반환합니다
(public member function)
(C++17) (C++20)
컨테이너나 배열의 크기를 반환합니다
(function template)
(C++17)
기본 배열에 대한 포인터를 얻습니다
(function template)