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

履歴 編集

function
<expected>

std::unexpected::swap(C++23)

constexpr void swap(unexpected& other)
  noexcept(is_nothrow_swappable_v<E>);

概要

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

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

is_swappable_v<E> == true

効果

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

using std::swap;
swap(unex, rhs.unex);

戻り値

なし

#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);
}

出力

バージョン

言語

  • C++23

処理系

参照