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

履歴 編集

function
<memory>

std::polymorphic::valueless_after_move(C++26)

constexpr bool valueless_after_move() const noexcept;

概要

*thisが無効値状態かどうかを判定する。polymorphicはムーブされたあとにのみ無効値状態となりうる。

戻り値

*thisが無効値状態であればtrue、そうでなければfalse

例外

投げない。

#include <cassert>
#include <memory>

struct Base {
  virtual ~Base() = default;
  virtual int f() const { return 0; }
};
struct Derived : Base {
  int x = 42;
  Derived() = default;
  Derived(int x) : x(x) {}
  int f() const override { return x; }
};

int main()
{
  std::polymorphic<Base> a{std::in_place_type<Derived>};
  assert(!a.valueless_after_move());

  std::polymorphic<Base> b = std::move(a);
  assert(a.valueless_after_move());  // ムーブ後は無効値状態
}

出力

バージョン

言語

  • C++26

処理系

関連項目

参照