std::inplace_vector<T,N>:: assign_range
From cppreference.net
<
cpp
|
container
|
inplace vector
|
template
<
container-compatible-range
<
T
>
R
>
constexpr void assign_range ( R && rg ) ; |
(C++26以降) | |
コンテナ内の要素を rg の各要素のコピーで置き換えます。
| このセクションは不完全です |
範囲内の各イテレータは、 rg 正確に1回デリファレンスされます。
rg が * this と重複する場合、動作は未定義です。
目次 |
パラメータ
| rg | - |
input_range
であり、参照型がコンテナの要素型に変換可能な範囲
|
| 型要件 | ||
|
-
|
||
-
T
が
EmplaceConstructible
ではなく、
*
ranges::
begin
(
rg
)
から
inplace_vector
内で構築できない場合、動作は未定義である。
|
||
例外
- std::bad_alloc 、もし std :: ranges:: distance ( rg ) > capacity ( ) の場合。
- 挿入された要素の初期化によってスローされるあらゆる例外。
例
このコードを実行
#include <algorithm> #include <cassert> #include <initializer_list> #include <inplace_vector> #include <iostream> #include <new> int main() { const auto source = {1, 2, 3}; std::inplace_vector<int, 4> destination{4, 5}; destination.assign_range(source); assert(std::ranges::equal(destination, source)); try { const auto bad = {-1, -2, -3, -4, -5}; destination.assign_range(bad); // 例外発生: bad.size() > destination.capacity() } catch(const std::bad_alloc& ex) { std::cout << ex.what() << '\n'; } }
出力例:
std::bad_alloc
関連項目
|
要素の範囲を挿入します
(公開メンバ関数) |
|
|
末尾に要素の範囲を追加します
(公開メンバ関数) |
|
|
コンテナに値を代入します
(公開メンバ関数) |
|
|
コンテナに値を代入します
(公開メンバ関数) |