Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d029cb
commit 469297f
Showing
3 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
* print[meta header] | ||
* std[meta namespace] | ||
* function template[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
template <class... Args> | ||
void print(format_string<Args...> fmt, | ||
Args&&... args); // (1) C++23 | ||
|
||
template <class... Args> | ||
void print(FILE* stream, | ||
format_string<Args...> fmt, | ||
Args&&... args); // (2) C++23 | ||
} | ||
``` | ||
* format_string[link /reference/format/format_string.md.nolink] | ||
* FILE[link /reference/cstdio/file.md.nolink] | ||
## 概要 | ||
書式指定で出力する。 | ||
書式は[`std::format()`](/reference/format/format.md)関数のページを参照。 | ||
この関数は、[`std::printf()`](/reference/cstdio/printf.md.nolink)関数ライクな書式指定で引数を文字列化して出力する。 | ||
- (1) : 標準出力に、書式指定で出力する | ||
- (2) : 指定された[`FILE`](/reference/cstdio/file.md.nolink)に、書式指定で出力する | ||
この関数は、末尾に改行コードが付かないことに注意。改行コードを自動で付けたい場合は、[`std::println()`](println.md)関数を使用すること。 | ||
[`std::ostream`](/reference/ostream/basic_ostream.md)から派生したクラスオブジェクトに対して出力したい場合は、[`<ostream>`](/reference/ostream.md)ヘッダの[`std::print()`](/reference/ostream/print.md.nolink)関数を使用すること。 | ||
## 効果 | ||
- (1) : 以下と等価: | ||
```cpp | ||
print(stdout, fmt, std::forward<Args>(args)...); | ||
``` | ||
* 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.nolink] | ||
* 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.nolink] | ||
* 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] | ||
|
||
|
||
## 備考 | ||
- LinuxやmacOSといった環境では、通常の`char`配列の文字列リテラルはUTF-8にエンコーディングされる | ||
- WindowsのVisual Studioにおいては、ソースコードと実行時文字集合をUTF-8にする[`/utf-8`オプション](https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170)を使用することで、通常の`char`配列の文字列リテラルがUTF-8にエンコーディングされる | ||
- 「通常の文字列リテラルがUTF-8エンコーディングされている場合」という仕様は、コードでは以下のように表現できる: | ||
``` | ||
constexpr bool is_utf8() { | ||
const unsigned char micro[] = "\u00B5"; | ||
return sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5; | ||
} | ||
template <typename... Args> | ||
void print(string_view fmt, const Args&... args) { | ||
if (is_utf8()) | ||
vprint_unicode(fmt, make_format_args(args...)); | ||
else | ||
vprint_nonunicode(fmt, make_format_args(args...)); | ||
} | ||
``` | ||
* vprint_unicode[link vprint_unicode.md.nolink] | ||
* vprint_nonunicode[link vprint_nonunicode.md.nolink] | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <print> | ||
|
||
int main() | ||
{ | ||
std::print("Hello {} World\n", 42); | ||
} | ||
``` | ||
* std::print[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
Hello 42 World | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 関連項目 | ||
- [`std::format()`](/reference/format/format.md) | ||
- [`std::println()`](println.md) | ||
|
||
|
||
## 参照 | ||
- [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# println | ||
* print[meta header] | ||
* std[meta namespace] | ||
* function template[meta id-type] | ||
* cpp23[meta cpp] | ||
|
||
```cpp | ||
namespace std { | ||
template <class... Args> | ||
void println(format_string<Args...> fmt, | ||
Args&&... args); // (1) C++23 | ||
|
||
template <class... Args> | ||
void println(FILE* stream, | ||
format_string<Args...> fmt, | ||
Args&&... args); // (2) C++23 | ||
} | ||
``` | ||
* format_string[link /reference/format/format_string.md.nolink] | ||
* FILE[link /reference/cstdio/file.md.nolink] | ||
## 概要 | ||
書式指定で出力する。この関数は、出力の末尾に改行コードが自動で付加される。 | ||
書式は[`std::format()`](/reference/format/format.md)関数のページを参照。 | ||
この関数は、[`std::printf()`](/reference/cstdio/printf.md.nolink)関数ライクな書式指定で引数を文字列化して出力する。 | ||
- (1) : 標準出力に、書式指定で出力する | ||
- (2) : 指定された[`FILE`](/reference/cstdio/file.md.nolink)に、書式指定で出力する | ||
この関数は、末尾に改行コードが付くことに注意。改行コードが不要な場合は、[`std::print()`](print.md)関数を使用すること。 | ||
[`std::ostream`](/reference/ostream/basic_ostream.md)から派生したクラスオブジェクトに対して出力したい場合は、[`<ostream>`](/reference/ostream.md)ヘッダの[`std::print()`](/reference/ostream/println.md.nolink)関数を使用すること。 | ||
## 効果 | ||
- (1) : 以下と等価: | ||
```cpp | ||
println(stdout, fmt, std::forward<Args>(args)...); | ||
``` | ||
* stdout[link /reference/cstdio/stdout.md.nolink] | ||
* std::forward[link /reference/utility/forward.md] | ||
|
||
- (2) : 以下と等価: | ||
```cpp | ||
print(stream, "{}\n", format(fmt, std::forward<Args>(args)...)); | ||
``` | ||
* print[link print.md] | ||
* format[link /reference/format/format.md] | ||
* std::forward[link /reference/utility/forward.md] | ||
|
||
|
||
## 例 | ||
```cpp example | ||
#include <print> | ||
|
||
int main() | ||
{ | ||
std::println("Hello {} World", 42); | ||
} | ||
``` | ||
* std::println[color ff0000] | ||
|
||
### 出力 | ||
``` | ||
Hello 42 World | ||
``` | ||
|
||
## バージョン | ||
### 言語 | ||
- C++23 | ||
|
||
### 処理系 | ||
- [Clang](/implementation.md#clang): ?? | ||
- [GCC](/implementation.md#gcc): ?? | ||
- [ICC](/implementation.md#icc): ?? | ||
- [Visual C++](/implementation.md#visual_cpp): ?? | ||
|
||
|
||
## 関連項目 | ||
- [`std::format()`](/reference/format/format.md) | ||
- [`std::print()`](print.md) | ||
|
||
|
||
## 参照 | ||
- [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html) |