std::inplace_vector<T,N>::inplace_vector
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을(를) 생성합니다.3)
inplace_vector을(를) 생성하고, 값이 count인 요소를 value개 복사합니다.4) 범위
inplace_vector의 내용으로 [first, last)을(를) 생성합니다.5) 범위
inplace_vector의 내용으로 rg을(를) 생성합니다./*container-compatible-range*/의 정의에 대해서는 ranges::to를 참고하십시오.ranges::size(rg)이 상수 표현식이고 N보다 크면 프로그램의 형식이 잘못되었습니다.6) 복사 생성자입니다.
inplace_vector의 내용을 복사하여 other을(를) 생성합니다.7) 이동 생성자입니다.
inplace_vector의 내용을 이동 의미론을 사용하여 other을(를) 생성합니다.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
에 선형적으로 비례합니다.
예외
예제
이 코드 실행
#include <cassert>
#include <initializer_list>
#include <inplace_vector>
#include <new>
#include <print>
#include <ranges>
int main()
{
std::inplace_vector<int, 4> v1; // overload (1)
assert(v1.size() == 0 && v1.capacity() == 4);
std::inplace_vector<int, 0> v2; // overload (1), N == 0 is allowed
assert(v2.size() == 0 && v2.capacity() == 0);
std::inplace_vector<int, 5> v3(3); // overload (2)
assert(v3.size() == 3 && v3.capacity() == 5);
std::println("v3 = {}", v3);
try
{
std::inplace_vector<int, 3> v(4); // overload (2), throws: count > N
}
catch(const std::bad_alloc& ex1)
{
std::println("ex1.what(): {}", ex1.what());
}
std::inplace_vector<int, 5> v4(3, 42); // overload (3)
assert(v4.size() == 3 && v4.capacity() == 5);
std::println("v4 = {}", v4);
try
{
std::inplace_vector<int, 3> v(4, 2); // overload (3), throws: 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()); // overload (4)
assert(v5.size() == 3 && v5.capacity() == 4);
std::println("v5 = {}", v5);
std::inplace_vector<int, 4> v6(std::from_range, init); // overload (5)
assert(v6.size() == 3 && v6.capacity() == 4);
std::println("v6 = {}", v6);
std::inplace_vector<int, 4> v7(v6); // overload (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)); // overload (7)
// Note that after the move v6 is left in valid but indeterminate state.
assert(v8.size() == 3 && v8.capacity() == 4);
std::println("v8 = {}", v8);
std::inplace_vector<int, 4> v9(init); // overload (8)
assert(v9.size() == 3 && v9.capacity() == 4);
std::println("v9 = {}", v9);
try
{
std::inplace_vector<int, 2> v(init); // overload (8), throws: 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) |