概要
書式設定をコピーする。
効果
*this
とrhs
が同じオブジェクトを指している場合、何もしない- C++03 :
this == &rhs
- C++11 :
this == addressof(rhs)
- C++03 :
- そうでなければ、以下のように引数
rhs
のメンバオブジェクトを*this
の対応するメンバオブジェクトに代入する。
以下、代入の詳細:
register_callback
で登録されているすべてのコールバックの組(fn, index)
について、(*fn)(erase_event, this, index)
の形式で呼び出す。- 以下の例外を除いて、引数
rhs
のメンバオブジェクトを*this
の対応するメンバオブジェクトに代入する。rdstate()
、rdbuf()
、exceptions()
は変更せずにそのままとする。pword
とiword
は、私用記憶域の内容をコピーする。rhs
から*this
にコピーされたポインタで、rhs
オブジェクトの外のオブジェクトを指していて、かつ、rhs
が破棄される際にrhs
と同時に破棄されるオブジェクトを指しているポインタは、当該ポインタが指すオブジェクトをコピーし、そのオブジェクトを指すように変更する。
register_callback
で登録されているすべてのコールバックの組(fn, index)
について、(*fn)(copyfmt_event, this, index)
の形式で呼び出す。exceptions(rhs.exceptions())
を呼び出す(結果として、ios_base::failure
例外が送出される可能性がある)。
戻り値
*this
備考
- 名前が示すように、書式設定はコピーするがストリームバッファ(
rdbuf
)、および、その状態(rdstate()
)はコピーしない。
ただし、exceptions()
は設定する。 - コールバックは
erase_event
とcopyfmt_event
の 2 回呼び出されるが、erase_event
で呼び出されるのはもともと*this
に登録されていたコールバック、copyfmt_event
で呼び出されるのはrhs
側に登録されていた(本関数で*this
にコピーされた)コールバックである。
erase_event
で、pword
の私用記憶域に格納されていたポインタが指すオブジェクトの破棄、copyfmt_event
でpword
の私用記憶域にコピーされたポインタが指すオブジェクトのコピー(あるいはポインタのヌルポインタへの変更)を行うことができる。
pword
の私用記憶域に格納したポインタの対処についてはios_base::pword
の例を参照。
例
#include <iostream>
#include <iomanip>
#include <cstddef>
int main()
{
std::ostream os(NULL);
os << std::hex << std::showbase << std::setw(10) << std::setfill('0') << std::internal;
std::cout.copyfmt(os);
std::cout << 10 << '\n';
}
12
#include <iostream>
#include <iomanip>
#include <cstddef>
int main()
{
std::ostream os(NULL);
os << std::hex << std::showbase << std::setw(10) << std::setfill('0') << std::internal;
std::cout.copyfmt(os);
std::cout << 10 << '\n';
}
出力
0x0000000a
バージョン
言語
- C++98
関連項目
basic_ios::rdstate
basic_ios::rdbuf
basic_ios::exceptions
ios_base::iword
ios_base::pword
ios_base::event
ios_base::event_callback
ios_base::register_callback