Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 1.1 KB

swap_free.md

File metadata and controls

65 lines (49 loc) · 1.1 KB

swap (非メンバ関数)

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

概要

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

効果

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

戻り値

なし

例

#include <cassert>
#include <expected>
#include <utility>

int main()
{
  std::unexpected<int> x{1};
  std::unexpected<int> y{2};
  assert(x.error() == 1 && y.error() == 2);

  std::swap(x, y);
  assert(x.error() == 2 && y.error() == 1);
}
  • std::swap[color ff0000]
  • error()[link error.md]
  • std::unexpected[link ../unexpected.md]

出力

バージョン

言語

  • C++23

処理系

参照