最終更新日時(UTC):
が更新

履歴 編集

class template
<ranges>

movable-box(C++23)

概要

movable-box は、規格の文中に現れる説明専用のクラスである。

movable-box<T> は、std::optional<T>とほとんど同じであるが、以下の差分をもつ。

差分1

テンプレートパラメーター制約 move_constructible<T> &&is_object_v<T> をもつ。

差分2

Tcopyableのモデルでない場合、コピー代入演算子は以下のように定義される。

constexpr movable-box& operator=(const movable-box& that) noexcept(is_nothrow_copy_constructible_v<T>) {
  if (this != addressof(that)) {
    if (that) emplace(*that);
    else reset();
  }
  return *this;
}

差分3

Tmovableのモデルでない場合、ムーブ代入演算子は以下のように定義される。

constexpr movable-box& operator=(movable-box&& that) noexcept(is_nothrow_move_constructible_v<T>) {
  if (this != addressof(that)) {
    if (that) emplace(std::move(*that));
    else reset();
  }
  return *this;
}

その他

以下のことが推奨される。

備考

このクラスは、copyable-boxを置き換える形で導入された。

バージョン

言語

  • C++23

参照