std::inplace_vector<T,N>::assign_range
ja.cppreference.net より
template< /*container-compatible-range*/<T> R >
constexpr void assign_range( R&& rg );
|
(C++26以降) | |
コンテナ内の要素を、rg 内の各要素のコピーで置き換えます。
| このセクションは不完全です |
範囲 rg 内の各イテレータはちょうど一回逆参照されます。
もしrgがコンテナと重なる場合、動作は未定義です。
パラメータ
| 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
関連項目
|
要素の範囲を挿入します
(公開メンバ関数) |
|
|
末尾に要素の範囲を追加します
(公開メンバ関数) |
|
|
コンテナに値を代入します
(公開メンバ関数) |
|
|
コンテナに値を代入します
(公開メンバ関数) |