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::basic_format_context - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. format
  3. basic_format_context

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

class template
<format>

std::basic_format_context(C++20)

namespace std {
  template<class Out, class charT>
  class basic_format_context; // (1)

  using format_context = basic_format_context<unspecified, char>; // (2)
  using wformat_context = basic_format_context<unspecified, wchar_t>; // (3)
}

概要

実際に渡されたフォーマット引数を含む、フォーマット実行中の状態を保持するクラス。

  • (1): テンプレートの定義
  • (2): マルチバイト文字列版の別名 (出力イテレータの型は未規定)
  • (3): ワイド文字列版の別名 (出力イテレータの型は未規定)

テンプレートパラメータ制約

  • OutはOutputIterator<const charT&>であること

備考

出力イテレータの型はフォーマット関数に指定したイテレータである必要はない。内部でバッファリングを行う実装が可能である。

C++26では、コピーコンストラクタとコピー代入演算子が= deleteで明示的に削除され、このクラスがコピー構築・コピー代入できないことが明確化された(これにともないムーブおよびデフォルト構築もできない)。

また、このクラステンプレートの明示的特殊化または部分特殊化をユーザーが宣言した場合、プログラムは不適格となる(診断不要)。

メンバ関数

名前 説明 対応バージョン
arg フォーマット引数を取得する C++20
out 出力イテレータを取得する C++20
advance_to 出力イテレータを指定したイテレータに設定する C++20
locale ロケールを取得する C++20

メンバ型

名前 説明 対応バージョン
iterator 出力イテレータ(Outと等しい) (type-alias) C++20
char_type 文字の型(charTと等しい) (type-alias) C++20
formatter_type 型Tに対応するフォーマッターの型 (alias-template) C++20

実装例

namespace std {
  template<class Out, class charT>
  class basic_format_context {
    basic_format_args<basic_format_context> args_;
    Out out_;
    std::optional<std::locale> locale;

  public:
    using iterator = Out;
    using char_type = charT;
    template<class T> using formatter_type = formatter<T, charT>;

    basic_format_context(iterator out, std::basic_format_args<basic_format_context> args, std::optional<std::locale> locale = std::nullopt)
      :args_(args)
      ,out_(out)
      ,locale_(locale)
    {
    }

    basic_format_arg<basic_format_context> arg(size_t id) const {
      return args_.get(id);
    }

    std::locale locale() {
      return locale_.value_or(std::locale());
    }

    iterator out() {
      return out_;
    }

    void advance_to(iterator it) {
      out_ = it;
    }
  };
}

バージョン

言語

  • C++20

処理系

  • Clang: ??
  • GCC: ??
  • Visual C++: ??

参照

  • P0645R10 Text Formatting
  • LWG Issue 3975. Specializations of basic_format_context should not be permitted
    • C++26で、ユーザーによる明示的特殊化・部分特殊化が不適格(診断不要)とされた
  • LWG Issue 4061. Should std::basic_format_context be default-constructible/copyable/movable?
    • C++26で、コピーコンストラクタとコピー代入演算子が= deleteで明示的に削除され、コピー・ムーブ・デフォルト構築ができないことが明確化された
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.