◐ Shell
clean mode source ↗

std::basic_stringbuf<CharT,Traits,Allocator>::operator= - cppreference.com

提供: cppreference.com

<tbody> </tbody>

std::basic_stringbuf& operator=( std::basic_stringbuf&& rhs );

(1) (C++11以上)

std::basic_stringbuf& operator=( const std::basic_stringbuf& rhs ) = delete;

(2)

1) ムーブ代入演算子。 rhs の内容を *this にムーブします。 ムーブの後、 *thisrhs がそれまで保持していた紐付けられた文字列、オープンモード、ロケール、およびその他のすべての状態を持ちます。 *this 内の std::basic_streambuf の6つのポインタはヌルでなければムーブされた rhs 内の対応するポインタと異なることが保証されます。

2) コピー代入演算子は削除されています。 basic_stringbufCopyAssignable ではありません。

引数

rhs - ムーブする別の basic_stringbuf

戻り値

*this

#include <sstream>
#include <string>
#include <iostream>

int main()
{

    std::istringstream one("one");
    std::ostringstream two("two");

    std::cout << "Before move, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";

    *one.rdbuf() = std::move(*two.rdbuf());

    std::cout << "After move, one = \"" << one.str() << '"'
              << " two = \"" << two.str() << "\"\n";
}

出力:

Before move, one = "one" two = "two"
After move, one = "two" two = ""

関連項目