Skip to content

Latest commit

 

History

History
91 lines (71 loc) · 4.7 KB

copyfmt.md

File metadata and controls

91 lines (71 loc) · 4.7 KB

copyfmt

  • ios[meta header]
  • std[meta namespace]
  • basic_ios[meta class]
  • function[meta id-type]
basic_ios& copyfmt(const basic_ios& rhs);
  • basic_ios[link ../basic_ios.md]

概要

書式設定をコピーする。

効果

  • *thisrhsが同じオブジェクトを指している場合、何もしない
    • C++03 : this == &rhs
    • C++11 : this == addressof(rhs)
  • そうでなければ、以下のように引数 rhs のメンバオブジェクトを *this の対応するメンバオブジェクトに代入する。

以下、代入の詳細:

  • register_callback で登録されているすべてのコールバックの組 (fn, index) について、(*fn)(erase_event, this, index) の形式で呼び出す。
  • 以下の例外を除いて、引数 rhs のメンバオブジェクトを *this の対応するメンバオブジェクトに代入する。
    • rdstate()rdbuf()exceptions() は変更せずにそのままとする。
    • pwordiword は、私用記憶域の内容をコピーする。
    • 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_eventcopyfmt_event の 2 回呼び出されるが、erase_event で呼び出されるのはもともと *this に登録されていたコールバック、copyfmt_event で呼び出されるのは rhs 側に登録されていた(本関数で *this にコピーされた)コールバックである。
    erase_event で、pword の私用記憶域に格納されていたポインタが指すオブジェクトの破棄、copyfmt_eventpword の私用記憶域にコピーされたポインタが指すオブジェクトのコピー(あるいはポインタのヌルポインタへの変更)を行うことができる。
    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';
}
  • copyfmt[color ff0000]
  • NULL[link ../../cstddef/null.md]
  • std::ostream[link ../../ostream/basic_ostream.md]
  • std::hex[link ../hex.md]
  • std::showbase[link ../showbase.md]
  • std::internal[link ../internal.md]
  • std::setw[link ../../iomanip/setw.md]
  • std::setfill[link ../../iomanip/setfill.md]

出力

0x0000000a

バージョン

言語

  • C++98

関連項目

参照