GeezerVison is showing cpprefjp.github.io — std::basic_format_context - cpprefjp C++日本語リファレンス
最終更新日時:
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 ;
}
};
}
バージョン
言語
処理系
参照