Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 1.41 KB

swap.md

File metadata and controls

70 lines (50 loc) · 1.41 KB

swap

  • tuple[meta header]
  • std[meta namespace]
  • tuple[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
void swap(tuple& rhs) noexcept(see below);           // (1) C++11
constexpr void swap(tuple& rhs) noexcept(see below); // (1) C++20
  • see below[italic]

概要

他のtupleオブジェクトと中身を入れ替える。

要件

tupleの全ての要素型がswap可能であること。

効果

自身のインスタンスの全ての要素を、rhsの全ての要素と入れ替える

戻り値

なし

例外

tupleの全ての要素型が、例外を投げないswapを持っている場合、この関数は例外を投げない

#include <string>
#include <tuple>
#include <cassert>

int main()
{
  std::tuple<int, char, std::string> a(1, 'a', "hello");
  std::tuple<int, char, std::string> b(2, 'b', "good-bye");

  a.swap(b);

  assert(a == std::make_tuple(2, 'b', "good-bye"));
  assert(b == std::make_tuple(1, 'a', "hello"));
}
  • swap[color ff0000]
  • std::make_tuple[link /reference/tuple/make_tuple.md]

出力

バージョン

言語

  • C++11

処理系

参照