Skip to content

Commit

Permalink
C++26対応として、enable_nonlocking_formatter_optimizationを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed Sep 11, 2024
1 parent 54bc557 commit 9119e06
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 30 deletions.
1 change: 1 addition & 0 deletions reference/chrono/duration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
## ハッシュサポート
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <class Rep, class Period>
inline constexpr bool enable_nonlocking_formatter_optimization<
chrono::duration<Rep, Period>> =
enable_nonlocking_formatter_optimization<Rep>;
}
```
## 概要
`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)
1 change: 1 addition & 0 deletions reference/chrono/zoned_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
## ハッシュサポート
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <class Duration>
inline constexpr bool enable_nonlocking_formatter_optimization<
chrono::zoned_time<Duration, const chrono::time_zone*>> = 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)
1 change: 1 addition & 0 deletions reference/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
68 changes: 68 additions & 0 deletions reference/format/enable_nonlocking_formatter_optimization.md
Original file line number Diff line number Diff line change
@@ -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 <class T>
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<T> = true;
```

Rangeに対しては、以下が定義される:

```cpp
template <ranges::input_range R>
requires (format_kind<R> != range_format::disabled)
inline constexpr bool enable_nonlocking_formatter_optimization<R> = 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 <class... Ts>
inline constexpr bool enable_nonlocking_formatter_optimization<pair-or-tuple<Ts...>> =
(enable_nonlocking_formatter_optimization<Ts> && ...);
```


## 備考
- ユーザーは、任意の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)
2 changes: 2 additions & 0 deletions reference/print.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

## バージョン
### 言語
Expand Down
63 changes: 46 additions & 17 deletions reference/print/print.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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>(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>(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>(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)`<Args>> && ...)`をもつ変数`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]


## 備考
Expand Down Expand Up @@ -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つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された
7 changes: 6 additions & 1 deletion reference/print/vprint_nonunicode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`に書き出す


## 例外
Expand Down Expand Up @@ -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つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された
52 changes: 52 additions & 0 deletions reference/print/vprint_nonunicode_buffered.md
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 25 additions & 12 deletions reference/print/vprint_unicode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)を送出する可能性がある

Expand Down Expand Up @@ -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つの提案文書では、余分な動的メモリ確保をしないよう仕様が見直された
Loading

0 comments on commit 9119e06

Please sign in to comment.