名前空間
変種
操作

std::vector<T,Allocator>::assign_range

From cppreference.com
< cpp‎ | コンテナ‎ | vector
 
 
 
 
template< container-compatible-range<T> R >
constexpr void assign_range( R&& rg );
(C++23から)

rg の各要素のコピーでコンテナの要素を置き換えます。

すべてのイテレータ(end() イテレータを含む)および要素へのすべての参照が無効になります。

rg の各イテレータはちょうど1回逆参照されます。

rg がコンテナと重なる場合、動作は未定義です。

目次

[編集] パラメータ

rg - コンテナの要素型に変換可能な参照型を持つinput_range
型要件
-
std::assignable_from<T&, ranges::range_reference_t<R>> がモデル化されている必要があります。そうでない場合、プログラムはill-formed(不正な形式)です。
-
T は、*ranges::begin(rg) からコンテナへEmplaceConstructible である必要があります。Rsized_rangeforward_range もモデル化しない場合、T はコンテナへ MoveInsertable でもある必要があります。それ以外の場合、動作は未定義です。

[編集] 戻り値

(なし)

注釈

機能テストマクロ 規格 機能
__cpp_lib_containers_ranges 202202L (C++23) ranges対応の構築と挿入

[編集]

#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));
}

[編集] 関連項目

要素の範囲を挿入する
(public member function)
末尾に要素の範囲を追加する
(public member function)
コンテナに値を代入する
(public member function)
コンテナに値を代入する
(public member function)
English 日本語 中文(简体) 中文(繁體)