Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.17 KB

swap_free.md

File metadata and controls

67 lines (51 loc) · 1.17 KB

swap (非メンバ関数)

  • expected[meta header]
  • function[meta id-type]
  • std[meta namespace]
  • expected[meta class]
  • cpp23[meta cpp]
friend constexpr void swap(expected& x, expected& y)
  noexcept(noexcept(x.swap(y)));
  • x.swap(y)[link swap.md]

概要

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

効果

x.swap(y);
  • swap[link swap.md]

戻り値

なし

#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);
}
  • std::swap[color ff0000]
  • value()[link value.md]
  • error()[link error.md]
  • std::unexpected[link ../unexpected.md]

出力

バージョン

言語

  • C++23

処理系

参照