std::inplace_vector<T,N>::assign_range
From cppreference.com
< cpp | container | inplace vector
| template< container-compatible-range<T> R > constexpr void assign_range( R&& rg ); |
(C++26以降) | |
rg の各要素のコピーでコンテナの要素を置き換えます。
| このセクションは未完成です |
rg の各イテレータはちょうど1回逆参照されます。
rg がコンテナと重なる場合、動作は未定義です。
目次 |
[編集] パラメータ
| rg | - | コンテナの要素型に変換可能な参照型を持つinput_range |
| 型要件 | ||
| -std::assignable_from<T&, ranges::range_reference_t<R>> がモデル化されている必要があります。そうでない場合、プログラムはill-formed(不正な形式)です。 | ||
-T は、*ranges::begin(rg) からコンテナにEmplaceConstructible である必要があります。そうでない場合、動作は未定義です。 | ||
[編集] 戻り値
(なし)
例外
- 容量を超える場合、bad_alloc を送出する。
- 挿入された要素の初期化によってスローされる可能性のある例外。
[編集] 例
このコードを実行
#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); // throws: bad.size() > destination.capacity() } catch(const std::bad_alloc& ex) { std::cout << ex.what() << '\n'; } }
実行結果の例
std::bad_alloc
[編集] 関連項目
| 要素の範囲を挿入する (public member function) | |
| 末尾に要素の範囲を追加する (public member function) | |
| コンテナに値を代入する (public member function) | |
| コンテナに値を代入する (public member function) |