std::basic_format_string, std::format_string, std::wformat_string
From cppreference.com
| ヘッダー <format> で定義 |
||
| template< class CharT, class... Args > struct basic_format_string; |
(1) | (C++20以降) |
| template< class... Args > using format_string = |
(2) | (C++20以降) |
| template< class... Args > using wformat_string = |
(3) | (C++20以降) |
クラス テンプレート std::basic_format_string は、書式化関数によって使用される std::basic_string_view をラップします。
std::basic_format_string のコンストラクタは、コンパイル時に書式指定文字列のチェックを実行します。ただし、コンストラクタ引数が std::runtime_format によって返される場合は除きます(C++26 以降)。
目次 |
[編集] メンバ関数
| (コンストラクタ) |
basic_format_string を構築し、引数が書式指定文字列でない場合はコンパイルエラーを発生させます。(public member function) |
| get |
ラップされた文字列を返します。 (public member function) |
std::basic_format_string::basic_format_string
| template< class T > consteval basic_format_string( const T& s ); |
(1) | |
| basic_format_string( /* runtime-format-string */<CharT> s ) noexcept; |
(2) | (C++26以降) |
1) 文字列 s のビューを格納する
basic_format_string オブジェクトを構築します。引数がコンパイル時定数でない場合、または書式化引数型 Args の書式指定文字列として解析できない場合、構築は不正です。 このオーバーロードは、const T& が std::convertible_to<std::basic_string_view<CharT>> をモデル化する場合にのみ、オーバーロード解決に参加します。
2) std::runtime_format によって返される文字列 s のビューを格納する
basic_format_string オブジェクトを構築します。構築時に書式指定文字列のチェックは実行されません。パラメータ
| s | - | フォーマット文字列を表すオブジェクト。フォーマット文字列は以下で構成される:
各置換フィールドは以下の形式を持つ。
1) フォーマット指定なしの置換フィールド
2) フォーマット指定ありの置換フィールド
| ||||||||||||||||||||||||||||||||||||||||||||||
std::basic_format_string::get
| constexpr std::basic_string_view<CharT> get() const noexcept; |
||
格納されている文字列ビューを返します。
[編集] 備考
エイリアス テンプレート format_string および wformat_string は、テンプレート引数推論を抑制するために std::type_identity_t を使用します。通常、これらが関数パラメータとして出現する場合、そのテンプレート引数は他の関数引数から推論されます。
template<class... Args> std::string format(std::format_string<Args...> fmt, Args&&... args); auto s = format("{} {}", 1.0, 2); // Calls format<double, int>. Args are deduced from 1.0, 2 // Due to the use of type_identity_t in format_string, template argument deduction // does not consider the type of the format string.
[編集] 例
| このセクションは未完成です 理由: 例がありません |
[編集] 欠陥報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| P2508R1 | C++20 | この機能にはユーザーから見える名前がない | basic_format_stringという名前が公開された |