std::inplace_vector<T,N>:: swap
From cppreference.net
<
cpp
|
container
|
inplace vector
C++
Containers library
|
(C++17)
|
||||
| Sequence | ||||
|
(C++11)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
(C++11)
|
||||
| Associative | ||||
| Unordered associative | ||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
|
(C++11)
|
||||
| Adaptors | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Views | ||||
|
(C++20)
|
||||
|
(C++23)
|
||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
std::inplace_vector
| Member types | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Non-member functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
constexpr
void
swap
(
inplace_vector
&
other
)
noexcept
(
/* see below */
)
;
|
(C++26以降) | |
コンテナの内容を other の内容と交換します。イテレータと参照が他のコンテナに関連付けられることはありません。
目次 |
パラメータ
| other | - | 内容を交換するコンテナ |
戻り値
(なし)
例外
noexcept
仕様:
noexcept
(
N
==
0
||
( std:: is_nothrow_swappable_v < T > && std:: is_nothrow_move_constructible_v < T > ) )
( std:: is_nothrow_swappable_v < T > && std:: is_nothrow_move_constructible_v < T > ) )
計算量
コンテナのサイズに対して線形。
例
このコードを実行
#include <inplace_vector> #include <print> int main() { std::inplace_vector<int, 3> a1{1, 2, 3}, a2{4, 5, 6}; auto i1 = a1.begin(); auto i2 = a2.begin(); int& r1 = a1[1]; int& r2 = a2[1]; auto print_them_all = [&](auto rem) { std::println("{}a1 = {}, a2 = {}, *i1 = {}, *i2 = {}, r1 = {}, r2 = {}", rem, a1, a2, *i1, *i2, r1, r2); }; print_them_all("Before swap:\n"); a1.swap(a2); print_them_all("After swap:\n"); // swap()後もイテレータと参照は元の要素に関連付けられたままであることに注意 // 例えば、i1は要素a1[0]を指し、r1はa1[1]を参照する }
出力:
Before swap: a1 = [1, 2, 3], a2 = [4, 5, 6], *i1 = 1, *i2 = 4, r1 = 2, r2 = 5 After swap: a1 = [4, 5, 6], a2 = [1, 2, 3], *i1 = 4, *i2 = 1, r1 = 5, r2 = 2
関連項目
|
(C++26)
|
std::swap
アルゴリズムを特殊化
(関数テンプレート) |