std::formatter<std::filesystem::path>
From cppreference.com
< cpp | filesystem | path
| ヘッダー <filesystem> で定義 |
||
| template< class CharT > struct formatter<std::filesystem::path, CharT>; |
(C++26以降) | |
std::formatter の std::filesystem::path クラスに対するテンプレート特殊化により、ユーザーはフォーマット関数を使用してパス名をそのテキスト表現に変換できます。この特殊化は デバッグ有効 です。
目次 |
[edit] フォーマット指定子
フォーマット指定子 path-format-spec の構文は次のとおりです。
fill-and-align (任意) width (任意) ?(任意) g(任意) |
|||||||||
fill-and-align および width は、標準フォーマット指定子と同じ意味を持ちます。
? オプションは、パス名を エスケープされた文字列としてフォーマットするために使用されます。
g オプションは、パス名が 汎用フォーマット表現であることを指定するために使用されます。
[edit] メンバ関数
| set_debug_format |
パス名を エスケープされた文字列としてフォーマットできるようにします。 (public member function) |
| parse |
path-format-spec で指定されたフォーマット指定子を解析します。 (public member function) |
| format |
path-format-spec で指定されたフォーマット済み出力を書き込みます。 (public member function) |
std::formatter<std::filesystem::path>::set_debug_format
| constexpr void set_debug_format(); |
||
現在のオブジェクトがパス名を エスケープされた文字列としてフォーマットできるようにします。
std::formatter<std::filesystem::path>::parse
| constexpr auto parse( std::basic_format_parse_context<CharT>& ctx ) -> std::basic_format_parse_context<CharT>::iterator; |
||
path-format-spec としてフォーマット指定子を解析し、解析された指定子を現在のオブジェクトに格納します。
path-format-spec の末尾以降のイテレータを返します。
std::formatter<std::filesystem::path>::format
| template< class FormatContext > auto format( const std::filesystem::path& p, FormatContext& ctx ) const |
||
g オプションが使用されている場合は s を p.generic<std::filesystem::path::value_type>() とし、それ以外の場合は p.native() とします。path-format-spec で指定されたとおりに s を ctx.out() に書き込みます。
パス名の文字変換について
- パス名は、ワイド文字文字列のネイティブエンコーディングから UTF-8 へ変換されます。この際、不正なサブシーケンスの最大部分置換は
U+FFFDREPLACEMENT CHARACTER で行われます。これは、以下の場合に発生します。- std::is_same_v<CharT, char> が true で、
- std::is_same_v<typename path::value_type, wchar_t> が true で、さらに
- 通常の文字列リテラルのエンコーディングが UTF-8 の場合。
- それ以外の場合、std::is_same_v<typename path::value_type, CharT> が true であれば、変換は行われません。
- それ以外の場合、変換は実装定義です。
出力範囲の末尾以降のイテレータを返します。
[edit] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_format_path |
202403L |
(C++26) | std::filesystem::path のフォーマットサポート |
[edit] 例
| このセクションは未完成です 理由: 例がありません |
[edit] 関連項目
| (C++20) |
与えられた型のフォーマット規則を定義する (クラステンプレート) |