Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 1.34 KB

File metadata and controls

73 lines (53 loc) · 1.34 KB

swap

  • expected[meta header]
  • function[meta id-type]
  • std[meta namespace]
  • unexpected[meta class]
  • cpp23[meta cpp]
constexpr void swap(unexpected& other)
  noexcept(is_nothrow_swappable_v<E>);
  • is_nothrow_swappable_v[link /reference/type_traits/is_nothrow_swappable.md]

概要

他のunexpectedオブジェクトとデータを入れ替える。

テンプレートパラメータ制約

is_swappable_v<E> == true

効果

動作説明用のE型メンバ変数unexとして、次と等価 :

using std::swap;
swap(unex, rhs.unex);
  • std::swap[link /reference/utility/swap.md]

戻り値

なし

#include <cassert>
#include <expected>

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

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

出力

バージョン

言語

  • C++23

処理系

参照