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