Files
cppdraft_translate/cppdraft/print/fun.md
2025-10-25 03:02:53 +03:00

6.7 KiB

[print.fun]

31 Input/output library [input.output]

31.7 Formatting and manipulators [iostream.format]

31.7.10 Print functions [print.fun]

🔗

template<class... Args> void print(format_string<Args...> fmt, Args&&... args);

1

#

Effects: Equivalent to:print(stdout, fmt, std::forward(args)...);

🔗

template<class... Args> void print(FILE* stream, format_string<Args...> fmt, Args&&... args);

2

#

Effects: Let locksafe be(enable_nonlocking_formatter_optimization<remove_cvref_t> && ...).

If the ordinary literal encoding ([lex.charset]) is UTF-8, equivalent to:locksafe ? vprint_unicode(stream, fmt.str, make_format_args(args...)): vprint_unicode_buffered(stream, fmt.str, make_format_args(args...));

Otherwise, equivalent to:locksafe ? vprint_nonunicode(stream, fmt.str, make_format_args(args...)): vprint_nonunicode_buffered(stream, fmt.str, make_format_args(args...));

🔗

template<class... Args> void println(format_string<Args...> fmt, Args&&... args);

3

#

Effects: Equivalent to:println(stdout, fmt, std::forward(args)...);

🔗

void println();

4

#

Effects: Equivalent to:println(stdout);

🔗

template<class... Args> void println(FILE* stream, format_string<Args...> fmt, Args&&... args);

5

#

Effects: Equivalent to:print(stream, runtime_format(string(fmt.get()) + '\n'), std::forward(args)...);

🔗

void println(FILE* stream);

6

#

Effects: Equivalent to:print(stream, "\n");

🔗

void vprint_unicode(string_view fmt, format_args args);

7

#

Effects: Equivalent to:vprint_unicode(stdout, fmt, args);

🔗

void vprint_unicode_buffered(FILE* stream, string_view fmt, format_args args);

8

#

Effects: Equivalent to:string out = vformat(fmt, args); vprint_unicode(stream, "{}", make_format_args(out));

🔗

void vprint_unicode(FILE* stream, string_view fmt, format_args args);

9

#

Preconditions: stream is a valid pointer to an output C stream.

10

#

Effects: Locks stream.

Let out denote the character representation of formatting arguments provided by args formatted according to specifications given in fmt.

  • (10.1)

    If stream refers to a terminal that is capable of displaying Unicode only via a native Unicode API, flushes stream and then writes out to the terminal using the native Unicode API; if out contains invalid code units,the behavior is undefined. Then establishes an observable checkpoint ([intro.abstract]).

  • (10.2)

    Otherwise writes out to stream unchanged.

Unconditionally unlocks stream on function exit.

See also: ISO/IEC 9899:2024, 7.21.2.

[Note 1:

On Windows the native Unicode API is WriteConsoleW andstream referring to a terminal means thatGetConsoleMode(_get_osfhandle(_fileno(stream)), ...) returns nonzero.

— end note]

11

#

Throws: Any exception thrown by the call to vformat ([format.err.report]).

system_error if writing to the terminal or stream fails.

May throw bad_alloc.

12

#

Recommended practice: If invoking the native Unicode API requires transcoding, implementations should substitute invalid code units with U+fffd replacement character per the Unicode Standard, Chapter 3.9 U+fffd Substitution in Conversion.

🔗

void vprint_nonunicode(string_view fmt, format_args args);

13

#

Effects: Equivalent to:vprint_nonunicode(stdout, fmt, args);

🔗

void vprint_nonunicode_buffered(FILE* stream, string_view fmt, format_args args);

14

#

Effects: Equivalent to:string out = vformat(fmt, args); vprint_nonunicode("{}", make_format_args(out));

🔗

void vprint_nonunicode(FILE* stream, string_view fmt, format_args args);

15

#

Preconditions: stream is a valid pointer to an output C stream.

16

#

Effects: While holding the lock on stream, writes the character representation of formatting arguments provided by args formatted according to specifications given in fmt to stream.

17

#

Throws: Any exception thrown by the call to vformat ([format.err.report]).

system_error if writing to stream fails.

May throw bad_alloc.