Skip to content

Commit a485eae

Browse files
committed
println : C++26対応として、改行コードのみを出力するオーバーロードを追加 (close #1335)
1 parent 35f7f21 commit a485eae

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

reference/ostream/println.md

+31
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace std {
1010
void println(ostream& os,
1111
format_string<Args...> fmt,
1212
Args&&... args); // (1) C++23
13+
14+
void println(ostream& os); // (2) C++26
1315
}
1416
```
1517
* format_string[link /reference/format/basic_format_string.md]
@@ -23,6 +25,7 @@ namespace std {
2325
この関数は、[`std::printf()`](/reference/cstdio/printf.md.nolink)関数ライクな書式指定で引数を文字列化して出力する。
2426
2527
- (1) : 指定した[`ostream`](basic_ostream.md)に、書式指定で出力する
28+
- (2) : 指定した[`ostream`](basic_ostream.md)に、改行コードを出力する
2629
2730
この関数は、末尾に改行コードが付くことに注意。改行コードが不要な場合は、[`std::print()`](print.md)関数を使用すること。
2831
@@ -38,6 +41,12 @@ namespace std {
3841
* format[link /reference/format/format.md]
3942
* std::forward[link /reference/utility/forward.md]
4043
44+
- (2) : 以下と等価:
45+
```cpp
46+
print(os, "\n");
47+
```
48+
* print[link print.md]
49+
4150
4251
## 例
4352
### 基本的な使い方
@@ -75,6 +84,27 @@ int main()
7584
Hello
7685
```
7786

87+
### 改行コードを出力する (C++26)
88+
```cpp example
89+
#include <iostream>
90+
91+
int main()
92+
{
93+
std::print(std::cout, "abc");
94+
std::println(std::cout, ); // 改行コードのみを出力する
95+
std::print(std::cout, "{}", 123);
96+
std::println(std::cout, );
97+
}
98+
```
99+
* std::print[link print.md]
100+
101+
#### 出力
102+
```
103+
abc
104+
123
105+
```
106+
107+
78108
## バージョン
79109
### 言語
80110
- C++23
@@ -94,3 +124,4 @@ Hello
94124

95125
## 参照
96126
- [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html)
127+
- [P3142R0 Printing Blank Lines with `println`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3142r0.pdf)

reference/print/println.md

+42-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ namespace std {
1010
void println(format_string<Args...> fmt,
1111
Args&&... args); // (1) C++23
1212

13+
void println(); // (2) C++26
14+
1315
template <class... Args>
1416
void println(FILE* stream,
1517
format_string<Args...> fmt,
16-
Args&&... args); // (2) C++23
18+
Args&&... args); // (3) C++23
19+
20+
void println(FILE* stream); // (4) C++26
1721
}
1822
```
1923
* format_string[link /reference/format/basic_format_string.md]
@@ -27,7 +31,9 @@ namespace std {
2731
この関数は、[`std::printf()`](/reference/cstdio/printf.md.nolink)関数ライクな書式指定で引数を文字列化して出力する。
2832
2933
- (1) : 標準出力に、書式指定で出力する
30-
- (2) : 指定された[`FILE`](/reference/cstdio/file.md.nolink)に、書式指定で出力する
34+
- (2) : 標準出力に改行コードを出力する
35+
- (3) : 指定された[`FILE`](/reference/cstdio/file.md.nolink)に、書式指定で出力する
36+
- (4) : 指定された[`FILE`](/reference/cstdio/file.md.nolink)に、改行コードを出力する
3137
3238
この関数は、末尾に改行コードが付くことに注意。改行コードが不要な場合は、[`std::print()`](print.md)関数を使用すること。
3339
@@ -43,13 +49,25 @@ namespace std {
4349
* std::forward[link /reference/utility/forward.md]
4450
4551
- (2) : 以下と等価:
52+
```cpp
53+
println(stdout);
54+
```
55+
* stdout[link /reference/cstdio/stdout.md.nolink]
56+
57+
- (3) : 以下と等価:
4658
```cpp
4759
print(stream, "{}\n", format(fmt, std::forward<Args>(args)...));
4860
```
4961
* print[link print.md]
5062
* format[link /reference/format/format.md]
5163
* std::forward[link /reference/utility/forward.md]
5264
65+
- (4) : 以下と等価:
66+
```cpp
67+
print(stream, "\n");
68+
```
69+
* print[link print.md]
70+
5371
5472
## 例
5573
### 基本的な使い方
@@ -113,6 +131,27 @@ int main()
113131
Hello
114132
```
115133

134+
135+
### 改行コードを出力する (C++26)
136+
```cpp example
137+
#include <print>
138+
139+
int main()
140+
{
141+
std::print("abc");
142+
std::println(); // 改行コードのみを出力する
143+
std::print("{}", 123);
144+
std::println();
145+
}
146+
```
147+
* std::print[link print.md]
148+
149+
#### 出力
150+
```
151+
abc
152+
123
153+
```
154+
116155
## バージョン
117156
### 言語
118157
- C++23
@@ -132,3 +171,4 @@ Hello
132171

133172
## 参照
134173
- [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html)
174+
- [P3142R0 Printing Blank Lines with `println`](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3142r0.pdf)

0 commit comments

Comments
 (0)