Namespaces
Variants

std::basic_stringbuf<CharT,Traits,Allocator>:: swap

From cppreference.net
void swap ( basic_stringbuf & rhs ) ;
(C++11以降)
(C++20まで)
void swap ( basic_stringbuf & rhs ) noexcept ( /* see below */ ) ;
(C++20以降)

* this rhs の状態と内容を交換します。

Allocator がswap時に伝播せず、かつ * this other のアロケータが等しくない場合、動作は未定義である。

(C++11以降)

目次

パラメータ

rhs - 別の basic_stringbuf

戻り値

(なし)

例外

実装定義の例外を送出する可能性があります。

(C++11以降)
(C++20まで)
noexcept 指定:
noexcept ( std:: allocator_traits < Allocator > :: propagate_on_container_swap :: value
|| std:: allocator_traits < Allocator > :: is_always_equal :: value )
(C++20以降)

注記

この関数は std::stringstream オブジェクトを交換する際に自動的に呼び出されます。直接呼び出す必要はほとんどありません。

#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
int main()
{
    std::istringstream one("one");
    std::ostringstream two("two");
    std::cout << "Before swap: one = " << std::quoted(one.str())
              << ", two = " << std::quoted(two.str()) << ".\n";
    one.rdbuf()->swap(*two.rdbuf());
    std::cout << "After  swap: one = " << std::quoted(one.str())
              << ", two = " << std::quoted(two.str()) << ".\n";
}

出力:

Before swap: one = "one", two = "two".
After  swap: one = "two", two = "one".

関連項目

basic_stringbuf オブジェクトを構築する
(public member function)
(C++11)
2つの文字列ストリームを交換する
( std::basic_stringstream<CharT,Traits,Allocator> のpublic member function)