Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 1.1 KB

swap_free.md

File metadata and controls

58 lines (43 loc) · 1.1 KB

swap (非メンバ関数)

  • string[meta header]
  • std[meta namespace]
  • function template[meta id-type]
namespace std {
    template <class CharT, class Traits, class Allocator>
  void swap(basic_string<CharT, Traits, Allocator>& x,
            basic_string<CharT, Traits, Allocator>& y);

  template <class CharT, class Traits, class Allocator>
  void swap(basic_string<CharT, Traits, Allocator>& x,
            basic_string<CharT, Traits, Allocator>& y)
    noexcept(noexcept(lhs.swap(rhs)));                 // C++17
}

概要

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

効果

x.swap(y)

戻り値

なし

#include <iostream>
#include <string>

int main()
{
  std::string a = "hello";
  std::string b = "world";

  std::swap(a, b);

  std::cout << a << std::endl;
  std::cout << b << std::endl;
}
  • std::swap[color ff0000]

出力

world
hello

参照