GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::swap (非メンバ関数) - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string
  3. basic_string
  4. swap (非メンバ関数)

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<string>

std::swap (非メンバ関数)

namespace std {
  template <class CharT, class Traits, class Allocator>
  void swap(basic_string<CharT, Traits, Allocator>& x,
            basic_string<CharT, Traits, Allocator>& y); // (1) C++98
  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)));                 // (1) C++17
  template <class CharT, class Traits, class Allocator>
  constexpr
  void swap(basic_string<CharT, Traits, Allocator>& x,
            basic_string<CharT, Traits, Allocator>& y)
    noexcept(noexcept(lhs.swap(rhs)));                 // (1) C++20
}

概要

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

出力

world
hello

参照

  • N4258 Cleaning-up noexcept in the Library, Rev 3
    • noexcept 追加の経緯となる提案文書
  • P0980R1 Making std::string constexpr
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.