From 9119e06bfc3ec280b28f12b785da0f188c5a6ab7 Mon Sep 17 00:00:00 2001 From: Akira Takahashi Date: Wed, 11 Sep 2024 16:03:22 +0900 Subject: [PATCH] =?UTF-8?q?C++26=E5=AF=BE=E5=BF=9C=E3=81=A8=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=80=81enable=5Fnonlocking=5Fformatter=5Foptimizatio?= =?UTF-8?q?n=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #1314 close #1334 --- reference/chrono/duration.md | 1 + ...nable_nonlocking_formatter_optimization.md | 30 ++++++++ reference/chrono/zoned_time.md | 1 + ...nable_nonlocking_formatter_optimization.md | 30 ++++++++ reference/format.md | 1 + ...nable_nonlocking_formatter_optimization.md | 68 +++++++++++++++++++ reference/print.md | 2 + reference/print/print.md | 63 ++++++++++++----- reference/print/vprint_nonunicode.md | 7 +- reference/print/vprint_nonunicode_buffered.md | 52 ++++++++++++++ reference/print/vprint_unicode.md | 37 ++++++---- reference/print/vprint_unicode_buffered.md | 52 ++++++++++++++ 12 files changed, 314 insertions(+), 30 deletions(-) create mode 100644 reference/chrono/duration/enable_nonlocking_formatter_optimization.md create mode 100644 reference/chrono/zoned_time/enable_nonlocking_formatter_optimization.md create mode 100644 reference/format/enable_nonlocking_formatter_optimization.md create mode 100644 reference/print/vprint_nonunicode_buffered.md create mode 100644 reference/print/vprint_unicode_buffered.md diff --git a/reference/chrono/duration.md b/reference/chrono/duration.md index eb94954025..8e109b71d2 100644 --- a/reference/chrono/duration.md +++ b/reference/chrono/duration.md @@ -156,6 +156,7 @@ namespace chrono { | 名前 | 説明 | 対応バージョン | |-------|--------------------|----------------| | [`formatter`](duration/formatter.md) | 文字列フォーマットの許可。[`std::formatter`](/reference/format/formatter.md)クラスの特殊化 | C++20 | +| [`enable_nonlocking_formatter_optimization`](duration/enable_nonlocking_formatter_optimization.md) | [`std::print()`](/reference/print/print.md)と[`std::println()`](/reference/print/println.md)の効率的な実装を有効にする | C++26 | ## ハッシュサポート diff --git a/reference/chrono/duration/enable_nonlocking_formatter_optimization.md b/reference/chrono/duration/enable_nonlocking_formatter_optimization.md new file mode 100644 index 0000000000..748f95ab59 --- /dev/null +++ b/reference/chrono/duration/enable_nonlocking_formatter_optimization.md @@ -0,0 +1,30 @@ +# enable_nonlocking_formatter_optimization +* chrono[meta header] +* std[meta namespace] +* variable[meta id-type] +* cpp26[meta cpp] + +```cpp +namespace std { + template + inline constexpr bool enable_nonlocking_formatter_optimization< + chrono::duration> = + enable_nonlocking_formatter_optimization; +} +``` + +## 概要 +`duration`クラスに対する[`std::enable_nonlocking_formatter_optimization`](/reference/format/enable_nonlocking_formatter_optimization.md)変数テンプレートの特殊化。 + + +## バージョン +### 言語 +- C++26 + +## 関連項目 +- [`std::enable_nonlocking_formatter_optimization`](/reference/format/enable_nonlocking_formatter_optimization.md) + + +## 参照 +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) diff --git a/reference/chrono/zoned_time.md b/reference/chrono/zoned_time.md index 1dcdadcff3..6fd7254a28 100644 --- a/reference/chrono/zoned_time.md +++ b/reference/chrono/zoned_time.md @@ -85,6 +85,7 @@ namespace std::chrono { | 名前 | 説明 | 対応バージョン | |------|------|----------------| | [`formatter`](zoned_time/formatter.md) | [`std::formatter`](/reference/format/formatter.md)クラスの特殊化 | C++20 | +| [`enable_nonlocking_formatter_optimization`](zoned_time/enable_nonlocking_formatter_optimization.md) | [`std::print()`](/reference/print/print.md)と[`std::println()`](/reference/print/println.md)の効率的な実装を有効にする | C++26 | ## ハッシュサポート diff --git a/reference/chrono/zoned_time/enable_nonlocking_formatter_optimization.md b/reference/chrono/zoned_time/enable_nonlocking_formatter_optimization.md new file mode 100644 index 0000000000..9ecafcccb3 --- /dev/null +++ b/reference/chrono/zoned_time/enable_nonlocking_formatter_optimization.md @@ -0,0 +1,30 @@ +# enable_nonlocking_formatter_optimization +* chrono[meta header] +* std[meta namespace] +* variable[meta id-type] +* cpp26[meta cpp] + +```cpp +namespace std { + template + inline constexpr bool enable_nonlocking_formatter_optimization< + chrono::zoned_time> = true; +} +``` +* chrono::time_zone[link /reference/chrono/time_zone.md] + +## 概要 +`zoned_time`クラスに対する[`std::enable_nonlocking_formatter_optimization`](/reference/format/enable_nonlocking_formatter_optimization.md)変数テンプレートの特殊化。 + + +## バージョン +### 言語 +- C++26 + +## 関連項目 +- [`std::enable_nonlocking_formatter_optimization`](/reference/format/enable_nonlocking_formatter_optimization.md) + + +## 参照 +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) diff --git a/reference/format.md b/reference/format.md index 35aac98b1e..4c533bd1ea 100644 --- a/reference/format.md +++ b/reference/format.md @@ -26,6 +26,7 @@ |----------------------------------------------------------------------|-----------------------------------------------------------------------------|----------------| | [`formattable`](format/formattable.md) | 文字列フォーマット可能 (concept) | C++23 | | [`formatter`](format/formatter.md) | 引数の型に対応する書式文字列の解析、値のフォーマットを担う (class template) | C++20 | +| [`enable_nonlocking_formatter_optimization`](format/enable_nonlocking_formatter_optimization.md) | [`std::print()`](/reference/print/print.md)と[`std::println()`](/reference/print/println.md)の効率的な実装を有効にする | C++26 | | [`basic_format_parse_context`](format/basic_format_parse_context.md) | 書式文字列の解析のコンテキスト (class template) | C++20 | | [`format_parse_context`](format/basic_format_parse_context.md) | `basic_format_parse_context`のマルチバイト文字列版 (type-alias) | C++20 | | [`wformat_parse_context`](format/basic_format_parse_context.md) | `basic_format_parse_context`のワイド文字列版 (type-alias) | C++20 | diff --git a/reference/format/enable_nonlocking_formatter_optimization.md b/reference/format/enable_nonlocking_formatter_optimization.md new file mode 100644 index 0000000000..3ac718bf4a --- /dev/null +++ b/reference/format/enable_nonlocking_formatter_optimization.md @@ -0,0 +1,68 @@ +# enable_nonlocking_formatter_optimization +* format[meta header] +* std[meta namespace] +* variable[meta id-type] +* cpp26[meta cpp] + +```cpp +namespace std { + template + constexpr bool enable_nonlocking_formatter_optimization = false; // (1) C++26 +} +``` + +## 概要 +[`std::print()`](/reference/print/print.md)と[`std::println()`](/reference/print/println.md)の効率的な実装を有効にする。 + +この値が`true`で定義される場合、文字列フォーマットされた文字列のストリームへの書き込み時に、余分な動的メモリ確保を行わない。 + +とくに指定されない限り、標準ライブラリで[`std::formatter`](formatter.md)の特殊化が定義される型に対して、各ヘッダは以下の特殊化を定義する: + +```cpp +template<> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +``` + +Rangeに対しては、以下が定義される: + +```cpp +template + requires (format_kind != range_format::disabled) +inline constexpr bool enable_nonlocking_formatter_optimization = false; +``` +* ranges::input_range[link /reference/ranges/input_range.md] +* format_kind[link format_kind.md] +* range_format[link range_format.md] + +[`std::pair`](/reference/utility/pair.md)および[`std::tuple`](/reference/tuple/tuple.md)に対しては、以下が定義される: + +```cpp +template +inline constexpr bool enable_nonlocking_formatter_optimization> = + (enable_nonlocking_formatter_optimization && ...); +``` + + +## 備考 +- ユーザーは、任意のCV修飾されないユーザー定義型でこの型の特殊化を定義できる + + +## バージョン +### 言語 +- C++26 + +### 処理系 +- [Clang](/implementation.md#clang): 18 [mark noimpl] +- [GCC](/implementation.md#gcc): 14 [mark noimpl] +- [Visual C++](/implementation.md#visual_cpp): 2022 Update 7 [mark noimpl] + + +## 関連項目 +- [`std::print()`](/reference/print/print.md) +- [`std::chrono::duration`に対する`enable_nonlocking_formatter_optimization`](/reference/chrono/duration/enable_nonlocking_formatter_optimization.md) +- [`std::chrono::zoned_time`に対する`enable_nonlocking_formatter_optimization`](/reference/chrono/zoned_time/enable_nonlocking_formatter_optimization.md) + + +## 参照 +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) diff --git a/reference/print.md b/reference/print.md index 961249f324..b2b96e9e09 100644 --- a/reference/print.md +++ b/reference/print.md @@ -12,7 +12,9 @@ | [`print`](print/print.md) | 書式指定で出力する (function template) | C++23 | | [`println`](print/println.md) | 書式指定で出力する。末尾改行付き (function template) | C++23 | | [`vprint_unicode`](print/vprint_unicode.md) | 書式指定でUnicode出力する (function) | C++23 | +| [`vprint_unicode_buffered`](print/vprint_nonunicode_buffered.md) | 確保した文字列バッファに書式指定の出力を作ってからUnicode出力する (function) | C++26 | | [`vprint_nonunicode`](print/vprint_nonunicode.md) | 書式指定で非Unicode出力する (function) | C++23 | +| [`vprint_nonunicode_buffered`](print/vprint_nonunicode_buffered.md) | 確保した文字列バッファに書式指定の出力を作ってから非Unicode出力する (function) | C++26 | ## バージョン ### 言語 diff --git a/reference/print/print.md b/reference/print/print.md index 359159b75c..87a33baa92 100644 --- a/reference/print/print.md +++ b/reference/print/print.md @@ -42,23 +42,49 @@ namespace std { * stdout[link /reference/cstdio/stdout.md.nolink] * std::forward[link /reference/utility/forward.md] -- (2) : 通常の文字列リテラルがUTF-8エンコーディングされている場合、以下と等価: - ```cpp - vprint_unicode(stream, fmt.get(), make_format_args(std::forward(args)...)); - ``` - * vprint_unicode[link vprint_unicode.md] - * fmt.get()[link /reference/format/format_string/get.md.nolink] - * make_format_args[link /reference/format/make_format_args.md] - * std::forward[link /reference/utility/forward.md] - - - そうでなければ、以下と等価: - ```cpp - vprint_nonunicode(stream, fmt.get(), make_format_args(std::forward(args)...)); - ``` - * vprint_nonunicode[link vprint_nonunicode.md] - * fmt.get()[link /reference/format/format_string/get.md.nolink] - * make_format_args[link /reference/format/make_format_args.md] - * std::forward[link /reference/utility/forward.md] +- (2) : + - C++23 : + - 通常の文字列リテラルがUTF-8エンコーディングされている場合、以下と等価: + ```cpp + vprint_unicode(stream, fmt.get(), make_format_args(std::forward(args)...)); + ``` + * vprint_unicode[link vprint_unicode.md] + * fmt.get()[link /reference/format/format_string/get.md.nolink] + * make_format_args[link /reference/format/make_format_args.md] + * std::forward[link /reference/utility/forward.md] + + - そうでなければ、以下と等価: + ```cpp + vprint_nonunicode(stream, fmt.get(), make_format_args(std::forward(args)...)); + ``` + * vprint_nonunicode[link vprint_nonunicode.md] + * fmt.get()[link /reference/format/format_string/get.md.nolink] + * make_format_args[link /reference/format/make_format_args.md] + * std::forward[link /reference/utility/forward.md] + + - C++26 : + - 値として`(`[`enable_nonlocking_formatter_optimization`](/reference/format/enable_nonlocking_formatter_optimization.md)`<`[`remove_cvref_t`](/reference/type_traits/remove_cvref.md)`> && ...)`をもつ変数`locksafe`があるとして、 + - 通常の文字列リテラルがUTF-8エンコーディングされている場合、以下と等価: + ```cpp + locksafe + ? vprint_unicode(stream, fmt.get(), make_format_args(args...)) + : vprint_unicode_buffered(stream, fmt.get(), make_format_args(args...)); + ``` + * vprint_unicode[link vprint_unicode.md] + * vprint_unicode_buffered[link vprint_unicode_buffered.md] + * fmt.get()[link /reference/format/format_string/get.md.nolink] + * make_format_args[link /reference/format/make_format_args.md] + + - そうでなければ、以下と等価: + ```cpp + locksafe + ? vprint_nonunicode(stream, fmt.get(), make_format_args(args...)) + : vprint_nonunicode_buffered(stream, fmt.get(), make_format_args(args...)); + ``` + * vprint_nonunicode[link vprint_nonunicode.md] + * vprint_nonunicode_buffered[link vprint_nonunicode_buffered.md] + * fmt.get()[link /reference/format/format_string/get.md.nolink] + * make_format_args[link /reference/format/make_format_args.md] ## 備考 @@ -164,3 +190,6 @@ Hello ## 参照 - [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html) +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) + - C++26の上記2つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された diff --git a/reference/print/vprint_nonunicode.md b/reference/print/vprint_nonunicode.md index bdeee9d6ba..8d7e459c3f 100644 --- a/reference/print/vprint_nonunicode.md +++ b/reference/print/vprint_nonunicode.md @@ -37,7 +37,9 @@ namespace std { ``` * stdout[link /reference/cstdio/stdout.md.nolink] -- (2) : [`vformat`](/reference/format/vformat.md)`(fmt, args)`の結果を`stream`に書き出す +- (2) : + - C++23 : [`vformat`](/reference/format/vformat.md)`(fmt, args)`の結果を`stream`に書き出す + - C++26 : ストリームのロックを保持したまま、`fmt`で書式指定に従って書式化された`args`の文字表現を`stream`に書き出す ## 例外 @@ -65,3 +67,6 @@ namespace std { ## 参照 - [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html) +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) + - C++26の上記2つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された diff --git a/reference/print/vprint_nonunicode_buffered.md b/reference/print/vprint_nonunicode_buffered.md new file mode 100644 index 0000000000..6521cbc1c6 --- /dev/null +++ b/reference/print/vprint_nonunicode_buffered.md @@ -0,0 +1,52 @@ +# vprint_nonunicode_buffered +* print[meta header] +* std[meta namespace] +* function[meta id-type] +* cpp26[meta cpp] + +```cpp +namespace std { + void vprint_nonunicode_buffered( + FILE* stream, + string_view fmt, + format_args args); // (1) C++26 +} +``` +* FILE[link /reference/cstdio/file.md.nolink] +* format_args[link /reference/format/basic_format_args.md] + +## 概要 +確保した文字列バッファに書式指定の出力を作ってから非Unicode出力する。 + + +## 効果 +- (1) : 以下と等価: + ```cpp + string out = vformat(fmt, args); + vprint_nonunicode("{}", make_format_args(out)); + ``` + * string[link /reference/string/basic_string.md] + * vformat[link /reference/format/vformat.md] + * vprint_nonunicode[link vprint_nonunicode.md] + * make_format_args[link /reference/format/make_format_args.md] + + +## バージョン +### 言語 +- C++26 + +### 処理系 +- [Clang](/implementation.md#clang): 18 [mark noimpl] +- [GCC](/implementation.md#gcc): 14 [mark noimpl] +- [Visual C++](/implementation.md#visual_cpp): 2022 Update 7 [mark noimpl] + + +## 関連項目 +- [`std::print()`](print.md) +- [`std::println()`](println.md) +- [`std::vprint_nonunicode()`](vprint_nonunicode.md) + + +## 参照 +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) diff --git a/reference/print/vprint_unicode.md b/reference/print/vprint_unicode.md index 652f0d9c1a..775af92699 100644 --- a/reference/print/vprint_unicode.md +++ b/reference/print/vprint_unicode.md @@ -37,20 +37,30 @@ namespace std { ``` * stdout[link /reference/cstdio/stdout.md.nolink] -- (2) : 以下の方法で自動変数を初期化する: - ```cpp - string out = vformat(fmt, args); - ``` - * string[link /reference/string/basic_string.md] - * vformat[link /reference/format/vformat.md] - - - `stream`がUnicodeを表示できる端末を参照している場合、ネイティブのUnicode APIを使用して端末に書き出す - - `out`に無効なコードユニットが含まれる場合、その動作は未定義であり,実装者はそれを診断することが推奨される。それ以外の場合は、変更せずにストリームに書き出す。そうでなければ、変更せず`stream`に`out`を書き出す。 - - ネイティブのUnicode APIを使用する場合、この関数は`out`を書き出す前にフラッシュする - +- (2) : + - C++23 : + - 以下の方法で自動変数を初期化する: + ```cpp + string out = vformat(fmt, args); + ``` + * string[link /reference/string/basic_string.md] + * vformat[link /reference/format/vformat.md] + + - `stream`がUnicodeを表示できる端末を参照している場合、ネイティブのUnicode APIを使用して端末に書き出す + - `out`に無効なコードユニットが含まれる場合、その動作は未定義であり,実装者はそれを診断することが推奨される。それ以外の場合は、変更せずにストリームに書き出す。そうでなければ、変更せず`stream`に`out`を書き出す。 + - ネイティブのUnicode APIを使用する場合、この関数は`out`を書き出す前にフラッシュする + + - C++26 : + - `stream`のロックを取得する + - `fmt`で書式指定に従って書式化された`args`の文字表現を`out`とする + - `stream`がUnicodeを表示できる端末を参照している場合、ネイティブのUnicode APIを使用して端末に書き出す + - `out`に無効なコードユニットが含まれる場合、その動作は未定義であり,実装者はそれを診断することが推奨される。それ以外の場合は、変更せずにストリームに書き出す。そうでなければ、変更せず`stream`に`out`を書き出す。 + - ネイティブのUnicode APIを使用する場合、この関数は`out`を書き出す前にフラッシュする + - 関数終了時に、無条件にロックを手放す ## 例外 -- [`vformat()`](/reference/format/vformat.md)関数がなんらかの例外を送出する可能性がある +- (2) : + - C++23 : [`vformat()`](/reference/format/vformat.md)関数がなんらかの例外を送出する可能性がある - 端末かストリームへの書き込みに失敗した場合、[`system_error`](/reference/system_error/system_error.md)を送出する - [`bad_alloc`](/reference/new/bad_alloc.md)を送出する可能性がある @@ -81,3 +91,6 @@ namespace std { ## 参照 - [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html) - [P2539R4 Should the output of `std::print` to a terminal be synchronized with the underlying stream?](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2539r4.html) +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html) + - C++26の上記2つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された diff --git a/reference/print/vprint_unicode_buffered.md b/reference/print/vprint_unicode_buffered.md new file mode 100644 index 0000000000..34fcb526ea --- /dev/null +++ b/reference/print/vprint_unicode_buffered.md @@ -0,0 +1,52 @@ +# vprint_unicode_buffered +* print[meta header] +* std[meta namespace] +* function[meta id-type] +* cpp26[meta cpp] + +```cpp +namespace std { + void vprint_unicode_buffered( + FILE* stream, + string_view fmt, + format_args args); // (1) C++26 +} +``` +* FILE[link /reference/cstdio/file.md.nolink] +* format_args[link /reference/format/basic_format_args.md] + +## 概要 +確保した文字列バッファに書式指定の出力を作ってからUnicode出力する。 + + +## 効果 +- (1) : 以下と等価: + ```cpp + string out = vformat(fmt, args); + vprint_unicode("{}", make_format_args(out)); + ``` + * string[link /reference/string/basic_string.md] + * vformat[link /reference/format/vformat.md] + * vprint_unicode[link vprint_unicode.md] + * make_format_args[link /reference/format/make_format_args.md] + + +## バージョン +### 言語 +- C++26 + +### 処理系 +- [Clang](/implementation.md#clang): 18 [mark noimpl] +- [GCC](/implementation.md#gcc): 14 [mark noimpl] +- [Visual C++](/implementation.md#visual_cpp): 2022 Update 7 [mark noimpl] + + +## 関連項目 +- [`std::print()`](print.md) +- [`std::println()`](println.md) +- [`std::vprint_unicode()`](vprint_unicode.md) + + +## 参照 +- [P3107R5 Permit an efficient implementation of `std::print`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3107r5.html) +- [P3235R3 `std::print` more types faster with less memory](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3235r3.html)