|
4162 | 4162 |
|
4163 | 4163 | template<class Ostream, class T>
|
4164 | 4164 | Ostream&& operator<<(Ostream&& os, const T& x);
|
| 4165 | + |
| 4166 | + template<class... Args> |
| 4167 | + void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4168 | + template<class... Args> |
| 4169 | + void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4170 | + |
| 4171 | + void vprint_unicode(ostream& os, string_view fmt, format_args args); |
| 4172 | + void vprint_nonunicode(ostream& os, string_view fmt, format_args args); |
4165 | 4173 | }
|
4166 | 4174 | \end{codeblock}
|
4167 | 4175 |
|
|
4203 | 4211 | }
|
4204 | 4212 | \end{codeblock}
|
4205 | 4213 |
|
| 4214 | +\rSec2[print.syn]{Header \tcode{<print>} synopsis} |
| 4215 | + |
| 4216 | +\indexheader{print}% |
| 4217 | +\begin{codeblock} |
| 4218 | +namespace std { |
| 4219 | + template<class... Args> |
| 4220 | + void print(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4221 | + template<class... Args> |
| 4222 | + void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4223 | + |
| 4224 | + template<class... Args> |
| 4225 | + void println(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4226 | + template<class... Args> |
| 4227 | + void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4228 | + |
| 4229 | + void vprint_unicode(string_view fmt, format_args args); |
| 4230 | + void vprint_unicode(FILE* stream, string_view fmt, format_args args); |
| 4231 | + |
| 4232 | + void vprint_nonunicode(string_view fmt, format_args args); |
| 4233 | + void vprint_nonunicode(FILE* stream, string_view fmt, format_args args); |
| 4234 | +} |
| 4235 | +\end{codeblock} |
| 4236 | + |
4206 | 4237 | \rSec2[input.streams]{Input streams}
|
4207 | 4238 |
|
4208 | 4239 | \rSec3[input.streams.general]{General}
|
|
7462 | 7493 | \end{itemize}
|
7463 | 7494 | \end{itemdescr}
|
7464 | 7495 |
|
| 7496 | +\rSec2[print.fun]{Print functions} |
| 7497 | + |
| 7498 | +\indexlibraryglobal{print}% |
| 7499 | +\begin{itemdecl} |
| 7500 | +template<class... Args> |
| 7501 | + void print(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7502 | +\end{itemdecl} |
| 7503 | + |
| 7504 | +\begin{itemdescr} |
| 7505 | +\pnum |
| 7506 | +\effects |
| 7507 | +Equivalent to: |
| 7508 | +\begin{codeblock} |
| 7509 | +print(stdout, fmt, std::forward<Args>(args)...); |
| 7510 | +\end{codeblock} |
| 7511 | +\end{itemdescr} |
| 7512 | + |
| 7513 | +\indexlibraryglobal{print}% |
| 7514 | +\begin{itemdecl} |
| 7515 | +template<class... Args> |
| 7516 | + void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7517 | +\end{itemdecl} |
| 7518 | + |
| 7519 | +\begin{itemdescr} |
| 7520 | +\pnum |
| 7521 | +\effects |
| 7522 | +If the ordinary literal encoding ([lex.charset]) is UTF-8, equivalent to: |
| 7523 | +\begin{codeblock} |
| 7524 | +vprint_unicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7525 | +\end{codeblock} |
| 7526 | +Otherwise, equivalent to: |
| 7527 | +\begin{codeblock} |
| 7528 | +vprint_nonunicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7529 | +\end{codeblock} |
| 7530 | +\end{itemdescr} |
| 7531 | + |
| 7532 | +\indexlibraryglobal{println}% |
| 7533 | +\begin{itemdecl} |
| 7534 | +template<class... Args> |
| 7535 | + void println(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7536 | +\end{itemdecl} |
| 7537 | + |
| 7538 | +\begin{itemdescr} |
| 7539 | +\pnum |
| 7540 | +\effects |
| 7541 | +Equivalent to: |
| 7542 | +\begin{codeblock} |
| 7543 | +println(stdout, fmt, std::forward<Args>(args)...); |
| 7544 | +\end{codeblock} |
| 7545 | +\end{itemdescr} |
| 7546 | + |
| 7547 | +\indexlibraryglobal{println}% |
| 7548 | +\begin{itemdecl} |
| 7549 | +template<class... Args> |
| 7550 | + void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7551 | +\end{itemdecl} |
| 7552 | + |
| 7553 | +\begin{itemdescr} |
| 7554 | +\pnum |
| 7555 | +\effects |
| 7556 | +Equivalent to: |
| 7557 | +\begin{codeblock} |
| 7558 | +print(stream, "{}\n", format(fmt, std::forward<Args>(args)...)); |
| 7559 | +\end{codeblock} |
| 7560 | +\end{itemdescr} |
| 7561 | + |
| 7562 | +\indexlibraryglobal{vprint_unicode}% |
| 7563 | +\begin{itemdecl} |
| 7564 | +void vprint_unicode(string_view fmt, format_args args); |
| 7565 | +\end{itemdecl} |
| 7566 | + |
| 7567 | +\begin{itemdescr} |
| 7568 | +\pnum |
| 7569 | +\effects |
| 7570 | +Equivalent to: |
| 7571 | +\begin{codeblock} |
| 7572 | +vprint_unicode(stdout, fmt, args); |
| 7573 | +\end{codeblock} |
| 7574 | +\end{itemdescr} |
| 7575 | + |
| 7576 | +\indexlibraryglobal{vprint_unicode}% |
| 7577 | +\begin{itemdecl} |
| 7578 | +void vprint_unicode(FILE* stream, string_view fmt, format_args args); |
| 7579 | +\end{itemdecl} |
| 7580 | + |
| 7581 | +\begin{itemdescr} |
| 7582 | +\pnum |
| 7583 | +\expects |
| 7584 | +\tcode{stream} is a valid pointer to an output C stream. |
| 7585 | + |
| 7586 | +\pnum |
| 7587 | +\effects |
| 7588 | +The function initializes an automatic variable via |
| 7589 | +\begin{codeblock} |
| 7590 | +string out = vformat(fmt, args); |
| 7591 | +\end{codeblock} |
| 7592 | +If \tcode{stream} refers to a terminal capable of displaying Unicode, |
| 7593 | +writes \tcode{out} to the terminal using the native Unicode API; |
| 7594 | +if \tcode{out} contains invalid code units, |
| 7595 | +\indextext{undefined}% |
| 7596 | +the behavior is undefined and |
| 7597 | +implementations are encouraged to diagnose it. |
| 7598 | +Otherwise writes \tcode{out} to \tcode{stream} unchanged. |
| 7599 | +\begin{note} |
| 7600 | +On POSIX and Windows, \tcode{stream} referring to a terminal means that, |
| 7601 | +respectively, |
| 7602 | +\tcode{isatty(fileno(\linebreak{}stream))} and |
| 7603 | +\tcode{GetConsoleMode(_get_osfhandle(_fileno(stream)), ...)} |
| 7604 | +return nonzero. |
| 7605 | +\end{note} |
| 7606 | +\begin{note} |
| 7607 | +On Windows, the native Unicode API is \tcode{WriteConsoleW}. |
| 7608 | +\end{note} |
| 7609 | + |
| 7610 | +\pnum |
| 7611 | +\throws |
| 7612 | +Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}. |
| 7613 | +\tcode{system_error} if writing to the terminal or \tcode{stream} fails. |
| 7614 | +May throw \tcode{bad_alloc}. |
| 7615 | + |
| 7616 | +\pnum |
| 7617 | +\recommended |
| 7618 | +If invoking the native Unicode API requires transcoding, |
| 7619 | +implementations should substitute invalid code units |
| 7620 | +with \unicode{fffd}{replacement character} per |
| 7621 | +The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9. |
| 7622 | +\end{itemdescr} |
| 7623 | + |
| 7624 | +\indexlibraryglobal{vprint_nonunicode}% |
| 7625 | +\begin{itemdecl} |
| 7626 | +void vprint_nonunicode(string_view fmt, format_args args); |
| 7627 | +\end{itemdecl} |
| 7628 | + |
| 7629 | +\begin{itemdescr} |
| 7630 | +\pnum |
| 7631 | +\effects |
| 7632 | +Equivalent to: |
| 7633 | +\begin{codeblock} |
| 7634 | +vprint_nonunicode(stdout, fmt, args); |
| 7635 | +\end{codeblock} |
| 7636 | +\end{itemdescr} |
| 7637 | + |
| 7638 | +\indexlibraryglobal{vprint_nonunicode}% |
| 7639 | +\begin{itemdecl} |
| 7640 | +void vprint_nonunicode(FILE* stream, string_view fmt, format_args args); |
| 7641 | +\end{itemdecl} |
| 7642 | + |
| 7643 | +\begin{itemdescr} |
| 7644 | +\pnum |
| 7645 | +\expects |
| 7646 | +\tcode{stream} is a valid pointer to an output C stream. |
| 7647 | + |
| 7648 | +\pnum |
| 7649 | +\effects |
| 7650 | +Writes the result of \tcode{vformat(fmt, args)} to \tcode{stream}. |
| 7651 | + |
| 7652 | +\pnum |
| 7653 | +\throws |
| 7654 | +Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}. |
| 7655 | +\tcode{system_error} if writing to \tcode{stream} fails. |
| 7656 | +May throw \tcode{bad_alloc}. |
| 7657 | +\end{itemdescr} |
| 7658 | + |
| 7659 | +\rSec2[ostream.formatted.print]{Print} |
| 7660 | + |
| 7661 | +\indexlibraryglobal{print}% |
| 7662 | +\begin{itemdecl} |
| 7663 | +template<class... Args> |
| 7664 | + void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7665 | +\end{itemdecl} |
| 7666 | + |
| 7667 | +\begin{itemdescr} |
| 7668 | +\pnum |
| 7669 | +\effects |
| 7670 | +If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to: |
| 7671 | +\begin{codeblock} |
| 7672 | +vprint_unicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7673 | +\end{codeblock} |
| 7674 | +Otherwise, equivalent to: |
| 7675 | +\begin{codeblock} |
| 7676 | +vprint_nonunicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7677 | +\end{codeblock} |
| 7678 | +\end{itemdescr} |
| 7679 | + |
| 7680 | +\indexlibraryglobal{println}% |
| 7681 | +\begin{itemdecl} |
| 7682 | +template<class... Args> |
| 7683 | + void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7684 | +\end{itemdecl} |
| 7685 | + |
| 7686 | +\begin{itemdescr} |
| 7687 | +\pnum |
| 7688 | +\effects |
| 7689 | +Equivalent to: |
| 7690 | +\begin{codeblock} |
| 7691 | +print(os, "{}\n", format(fmt, std::forward<Args>(args)...)); |
| 7692 | +\end{codeblock} |
| 7693 | +\end{itemdescr} |
| 7694 | + |
| 7695 | +\indexlibraryglobal{vprint_unicode}% |
| 7696 | +\indexlibraryglobal{vprint_nonunicode}% |
| 7697 | +\begin{itemdecl} |
| 7698 | +void vprint_unicode(ostream& os, string_view fmt, format_args args); |
| 7699 | +void vprint_nonunicode(ostream& os, string_view fmt, format_args args); |
| 7700 | +\end{itemdecl} |
| 7701 | + |
| 7702 | +\begin{itemdescr} |
| 7703 | +\pnum |
| 7704 | +\effects |
| 7705 | +Behaves as a formatted output function\iref{ostream.formatted.reqmts} |
| 7706 | +of \tcode{os}, except that: |
| 7707 | +\begin{itemize} |
| 7708 | +\item |
| 7709 | +failure to generate output is reported as specified below, and |
| 7710 | +\item |
| 7711 | +any exception thrown by the call to \tcode{vformat} is propagated |
| 7712 | +without regard to the value of \tcode{os.exceptions()} and |
| 7713 | +without turning on \tcode{ios_base::badbit} in the error state of \tcode{os}. |
| 7714 | +\end{itemize} |
| 7715 | +After constructing a \tcode{sentry} object, |
| 7716 | +the function initializes an automatic variable via |
| 7717 | +\begin{codeblock} |
| 7718 | +string out = vformat(os.getloc(), fmt, args); |
| 7719 | +\end{codeblock} |
| 7720 | +If the function is \tcode{vprint_unicode} and |
| 7721 | +\tcode{os} is a stream that refers to a terminal capable of displaying Unicode |
| 7722 | +which is determined in an implementation-defined manner, |
| 7723 | +writes \tcode{out} to the terminal using the native Unicode API; |
| 7724 | +if \tcode{out} contains invalid code units, |
| 7725 | +\indextext{undefined}% |
| 7726 | +the behavior is undefined and |
| 7727 | +implementations are encouraged to diagnose it. |
| 7728 | +Otherwise (if \tcode{os} is not such a stream or |
| 7729 | +the function is \tcode{vprint_nonunicode}), |
| 7730 | +inserts the character sequence |
| 7731 | +\tcode{[out.begin(), out.end())} into \tcode{os}. |
| 7732 | +If writing to the terminal or inserting into \tcode{os} fails, |
| 7733 | +calls \tcode{os.setstate(ios_base::badbit)} |
| 7734 | +(which may throw \tcode{ios_base::failure}). |
| 7735 | + |
| 7736 | +\pnum |
| 7737 | +\recommended |
| 7738 | +For \tcode{vprint_unicode}, |
| 7739 | +if invoking the native Unicode API requires transcoding, |
| 7740 | +implementations should substitute invalid code units |
| 7741 | +with \unicode{fffd}{replacement character} per |
| 7742 | +The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9. |
| 7743 | +\end{itemdescr} |
| 7744 | + |
7465 | 7745 | \rSec1[string.streams]{String-based streams}
|
7466 | 7746 |
|
7467 | 7747 | \rSec2[sstream.syn]{Header \tcode{<sstream>} synopsis}
|
|
0 commit comments