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

履歴 編集

function
<expected>

std::expected::swap (非メンバ関数)(C++23)

friend constexpr void swap(expected& x, expected& y)
  noexcept(noexcept(x.swap(y)));

概要

2つのexpectedオブジェクトを入れ替える。

効果

x.swap(y);

戻り値

なし

#include <cassert>
#include <expected>
#include <string>

int main()
{
  std::expected<int, std::string> x = 42;
  std::expected<int, std::string> y = std::unexpected{"ERR"};
  assert(x.value() == 42 && y.error() == "ERR");

  std::swap(x, y);
  assert(x.error() == "ERR" && y.value() == 42);
}

出力

バージョン

言語

  • C++23

処理系

参照