Namespaces
Variants

std::inplace_vector<T,N>::operator=

ja.cppreference.net より
 
 
 
 
constexpr inplace_vector& operator=( const inplace_vector& other );
(1) (C++26 から)
constexpr inplace_vector& operator=( inplace_vector&& other )
    noexcept(/* see below */);
(2) (C++26 から)
constexpr inplace_vector& operator=( std::initializer_list<T> init );
(3) (C++26 から)

の内容を置き換えるinplace_vector。

1) コピー代入演算子。 の内容のコピーで内容を置き換えるother。
この演算子は trivial であり、std::inplace_vector<T, N> がトリビアルなデストラクタを持ち、かつ std::is_trivially_copy_constructible_v<T> && std::is_trivially_copy_assignable_v<T> が true である場合に限ります。
2) ムーブ代入演算子。 ムーブセマンティクスを使用して other の内容で置き換える(すなわち、other のデータが other からこのコンテナにムーブされる)。other はその後、有効だが未規定の状態になる。
この演算子は trivial であり、std::inplace_vector<T, N> がトリビアルなデストラクタを持ち、かつ std::is_trivially_move_constructible_v<T> && std::is_trivially_move_assignable_v<T> が true である場合に限ります。
3) 初期化子リスト init で指定された内容で置き換える。

パラメータ

other - コンテナの要素を初期化するためのソースとして使用する別の inplace_vector
init - コンテナの要素を初期化するための初期化子リスト

計算量

1,2) * this と other のサイズに対して線形時間。
3) * this および init のサイズに対して線形。

例外

2)
変更点: - "specification:" → "noexcept指定:" - HTMLタグ、属性、タグ内のC++コードは一切翻訳せず保持 - C++固有の用語(noexcept、std::is_nothrow_move_assignable_v、std::is_nothrow_move_constructible_vなど)は翻訳せず保持 - 元のフォーマットと構造を完全に維持
3) 例外 std::bad_alloc がスローされる条件: init. size ( ) > N の場合。
翻訳のポイント: - "Throws" → 「例外」と訳し、自然な日本語の文脈に合わせて「がスローされる条件:」と補完 - HTMLタグ、属性、タグ内のC++コードは完全に保持 - 技術文書としての正確性と専門性を維持 - 日本語として自然な語順と表現になるよう調整

例

#include <initializer_list>
#include <inplace_vector>
#include <new>
#include <print>
#include <ranges>
#include <string>
int main()
{
    std::inplace_vector<int, 4> x({1, 2, 3}), y;
    std::println("初期状態:");
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::println("コピー代入によりxからyへデータをコピー:");
    y = x; // オーバーロード (1)
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::inplace_vector<std::string, 3> z, w{"\N{CAT}", "\N{GREEN HEART}"};
    std::println("初期状態:");
    std::println("z = {}", z);
    std::println("w = {}", w);
    std::println("ムーブ代入によりwからzへデータを移動:");
    z = std::move(w); // オーバーロード (2)
    std::println("z = {}", z);
    std::println("w = {}", w); // wは有効だが未規定の状態
    auto l = {4, 5, 6, 7};
    std::println("initializer_list {} のxへの代入:", l);
    x = l; // オーバーロード (3)
    std::println("x = {}", x);
    std::println("Nより大きいサイズのinitializer_listの代入は例外を送出:");
    try
    {
        x = {1, 2, 3, 4, 5}; // 送出: (初期化子リストサイズ == 5) > (容量 N == 4)
    }
    catch(const std::bad_alloc& ex)
    {
        std::println("ex.what(): {}", ex.what());
    }
}

出力例:

初期状態:
x = [1, 2, 3]
y = []
コピー代入によりxからyへデータをコピー:
x = [1, 2, 3]
y = [1, 2, 3]
初期状態:
z = []
w = ["🐈", "💚"]
ムーブ代入によりwからzへデータを移動:
z = ["🐈", "💚"]
w = ["", ""]
initializer_list [4, 5, 6, 7] のxへの代入:
x = [4, 5, 6, 7]
Nより大きいサイズのinitializer_listの代入は例外を送出:
ex.what(): std::bad_alloc

関連項目

inplace_vectorを構築する
(公開メンバ関数)
コンテナに値を代入する
(公開メンバ関数)