Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 846 Bytes

File metadata and controls

56 lines (44 loc) · 846 Bytes

swap (非メンバ関数)

  • any[meta header]
  • std[meta namespace]
  • function template[meta id-type]
  • cpp17[meta cpp]
namespace std {
  void swap(any& x, any& y) noexcept;
}

概要

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

効果

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

#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;
}
  • std::swap[color ff0000]
  • std::any_cast[link /reference/any/any_cast.md]

出力

Hello
3

バージョン

言語

  • C++17

処理系