std::vector<T,Allocator>:: assign_range
From cppreference.net
|
template
<
container-compatible-range
<
T
>
R
>
constexpr void assign_range ( R && rg ) ; |
(C++23以降) | |
コンテナ内の要素を rg の各要素のコピーで置き換えます。
すべてのイテレータ(
end()
イテレータを含む)および要素へのすべての参照が無効化されます。
範囲内の各イテレータは、 rg 正確に1回デリファレンスされます。
rg が * this とオーバーラップする場合、動作は未定義です。
目次 |
パラメータ
| rg | - |
参照型がコンテナの要素型に変換可能な
input_range
|
| 型要件 | ||
|
-
|
||
-
T
が
EmplaceConstructible
を
vector
に対して
*
ranges::
begin
(
rg
)
から満たさない場合、動作は未定義である。
|
||
-
T
が
MoveInsertable
を
vector
に対して満たさない場合、動作は未定義である:
| ||
|
(C++26まで) | |
|
(C++26以降) | |
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 構築と挿入 |
例
このコードを実行
#include <algorithm> #include <cassert> #include <vector> #include <list> int main() { const auto source = std::list{2, 7, 1}; auto destination = std::vector{3, 1, 4}; #ifdef __cpp_lib_containers_ranges destination.assign_range(source); #else destination.assign(source.cbegin(), source.cend()); #endif assert(std::ranges::equal(source, destination)); }
関連項目
|
(C++23)
|
要素の範囲を挿入する
(公開メンバ関数) |
|
(C++23)
|
末尾に要素の範囲を追加する
(公開メンバ関数) |
|
コンテナに値を割り当てる
(公開メンバ関数) |
|
|
コンテナに値を割り当てる
(公開メンバ関数) |