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

履歴 編集

function template
<any>

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

namespace std {
  void swap(any& x, any& y) noexcept;
}

概要

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

効果

x.swap(y);

#include <iostream>
#include <any>

int main()
{
  std::any x = 3;
  std::any y = "Hello";

  std::swap(x, y);

  std::cout << std::any_cast<const char*>(x) << std::endl;
  std::cout << std::any_cast<int>(y) << std::endl;
}

出力

Hello
3

バージョン

言語

  • C++17

処理系