|
4162 | 4162 |
|
4163 | 4163 | template<class Ostream, class T>
|
4164 | 4164 | Ostream&& operator<<(Ostream&& os, const T& x);
|
| 4165 | + |
| 4166 | + // \ref{ostream.formatted.print}, print functions |
| 4167 | + template<class... Args> |
| 4168 | + void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4169 | + template<class... Args> |
| 4170 | + void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4171 | + |
| 4172 | + void vprint_unicode(ostream& os, string_view fmt, format_args args); |
| 4173 | + void vprint_nonunicode(ostream& os, string_view fmt, format_args args); |
4165 | 4174 | }
|
4166 | 4175 | \end{codeblock}
|
4167 | 4176 |
|
|
4203 | 4212 | }
|
4204 | 4213 | \end{codeblock}
|
4205 | 4214 |
|
| 4215 | +\rSec2[print.syn]{Header \tcode{<print>} synopsis} |
| 4216 | + |
| 4217 | +\indexheader{print}% |
| 4218 | +\begin{codeblock} |
| 4219 | +namespace std { |
| 4220 | + // \ref{print.fun}, print functions |
| 4221 | + template<class... Args> |
| 4222 | + void print(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4223 | + template<class... Args> |
| 4224 | + void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4225 | + |
| 4226 | + template<class... Args> |
| 4227 | + void println(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4228 | + template<class... Args> |
| 4229 | + void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 4230 | + |
| 4231 | + void vprint_unicode(string_view fmt, format_args args); |
| 4232 | + void vprint_unicode(FILE* stream, string_view fmt, format_args args); |
| 4233 | + |
| 4234 | + void vprint_nonunicode(string_view fmt, format_args args); |
| 4235 | + void vprint_nonunicode(FILE* stream, string_view fmt, format_args args); |
| 4236 | +} |
| 4237 | +\end{codeblock} |
| 4238 | + |
4206 | 4239 | \rSec2[input.streams]{Input streams}
|
4207 | 4240 |
|
4208 | 4241 | \rSec3[input.streams.general]{General}
|
|
6767 | 6800 | \tcode{out}.
|
6768 | 6801 | \end{itemdescr}
|
6769 | 6802 |
|
| 6803 | +\rSec4[ostream.formatted.print]{Print} |
| 6804 | + |
| 6805 | +\indexlibraryglobal{print}% |
| 6806 | +\begin{itemdecl} |
| 6807 | +template<class... Args> |
| 6808 | + void print(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 6809 | +\end{itemdecl} |
| 6810 | + |
| 6811 | +\begin{itemdescr} |
| 6812 | +\pnum |
| 6813 | +\effects |
| 6814 | +If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to: |
| 6815 | +\begin{codeblock} |
| 6816 | +vprint_unicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 6817 | +\end{codeblock} |
| 6818 | +Otherwise, equivalent to: |
| 6819 | +\begin{codeblock} |
| 6820 | +vprint_nonunicode(os, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 6821 | +\end{codeblock} |
| 6822 | +\end{itemdescr} |
| 6823 | + |
| 6824 | +\indexlibraryglobal{println}% |
| 6825 | +\begin{itemdecl} |
| 6826 | +template<class... Args> |
| 6827 | + void println(ostream& os, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 6828 | +\end{itemdecl} |
| 6829 | + |
| 6830 | +\begin{itemdescr} |
| 6831 | +\pnum |
| 6832 | +\effects |
| 6833 | +Equivalent to: |
| 6834 | +\begin{codeblock} |
| 6835 | +print(os, "{}\n", format(fmt, std::forward<Args>(args)...)); |
| 6836 | +\end{codeblock} |
| 6837 | +\end{itemdescr} |
| 6838 | + |
| 6839 | +\indexlibraryglobal{vprint_unicode}% |
| 6840 | +\indexlibraryglobal{vprint_nonunicode}% |
| 6841 | +\begin{itemdecl} |
| 6842 | +void vprint_unicode(ostream& os, string_view fmt, format_args args); |
| 6843 | +void vprint_nonunicode(ostream& os, string_view fmt, format_args args); |
| 6844 | +\end{itemdecl} |
| 6845 | + |
| 6846 | +\begin{itemdescr} |
| 6847 | +\pnum |
| 6848 | +\effects |
| 6849 | +Behaves as a formatted output function\iref{ostream.formatted.reqmts} |
| 6850 | +of \tcode{os}, except that: |
| 6851 | +\begin{itemize} |
| 6852 | +\item |
| 6853 | +failure to generate output is reported as specified below, and |
| 6854 | +\item |
| 6855 | +any exception thrown by the call to \tcode{vformat} is propagated |
| 6856 | +without regard to the value of \tcode{os.exceptions()} and |
| 6857 | +without turning on \tcode{ios_base::badbit} in the error state of \tcode{os}. |
| 6858 | +\end{itemize} |
| 6859 | +After constructing a \tcode{sentry} object, |
| 6860 | +the function initializes an automatic variable via |
| 6861 | +\begin{codeblock} |
| 6862 | +string out = vformat(os.getloc(), fmt, args); |
| 6863 | +\end{codeblock} |
| 6864 | +If the function is \tcode{vprint_unicode} and |
| 6865 | +\tcode{os} is a stream that refers to a terminal capable of displaying Unicode |
| 6866 | +which is determined in an implementation-defined manner, |
| 6867 | +writes \tcode{out} to the terminal using the native Unicode API; |
| 6868 | +if \tcode{out} contains invalid code units, |
| 6869 | +\indextext{undefined}% |
| 6870 | +the behavior is undefined and |
| 6871 | +implementations are encouraged to diagnose it. |
| 6872 | +Otherwise (if \tcode{os} is not such a stream or |
| 6873 | +the function is \tcode{vprint_nonunicode}), |
| 6874 | +inserts the character sequence |
| 6875 | +\range{out.begin()}{out.end()} into \tcode{os}. |
| 6876 | +If writing to the terminal or inserting into \tcode{os} fails, |
| 6877 | +calls \tcode{os.setstate(ios_base::badbit)} |
| 6878 | +(which may throw \tcode{ios_base::failure}). |
| 6879 | + |
| 6880 | +\pnum |
| 6881 | +\recommended |
| 6882 | +For \tcode{vprint_unicode}, |
| 6883 | +if invoking the native Unicode API requires transcoding, |
| 6884 | +implementations should substitute invalid code units |
| 6885 | +with \unicode{fffd}{replacement character} per |
| 6886 | +The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9. |
| 6887 | +\end{itemdescr} |
| 6888 | + |
6770 | 6889 | \rSec3[ostream.unformatted]{Unformatted output functions}
|
6771 | 6890 |
|
6772 | 6891 | \pnum
|
|
7573 | 7692 | \end{itemize}
|
7574 | 7693 | \end{itemdescr}
|
7575 | 7694 |
|
| 7695 | +\rSec2[print.fun]{Print functions} |
| 7696 | + |
| 7697 | +\indexlibraryglobal{print}% |
| 7698 | +\begin{itemdecl} |
| 7699 | +template<class... Args> |
| 7700 | + void print(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7701 | +\end{itemdecl} |
| 7702 | + |
| 7703 | +\begin{itemdescr} |
| 7704 | +\pnum |
| 7705 | +\effects |
| 7706 | +Equivalent to: |
| 7707 | +\begin{codeblock} |
| 7708 | +print(stdout, fmt, std::forward<Args>(args)...); |
| 7709 | +\end{codeblock} |
| 7710 | +\end{itemdescr} |
| 7711 | + |
| 7712 | +\indexlibraryglobal{print}% |
| 7713 | +\begin{itemdecl} |
| 7714 | +template<class... Args> |
| 7715 | + void print(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7716 | +\end{itemdecl} |
| 7717 | + |
| 7718 | +\begin{itemdescr} |
| 7719 | +\pnum |
| 7720 | +\effects |
| 7721 | +If the ordinary literal encoding\iref{lex.charset} is UTF-8, equivalent to: |
| 7722 | +\begin{codeblock} |
| 7723 | +vprint_unicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7724 | +\end{codeblock} |
| 7725 | +Otherwise, equivalent to: |
| 7726 | +\begin{codeblock} |
| 7727 | +vprint_nonunicode(stream, fmt.@\exposid{str}@, make_format_args(std::forward<Args>(args)...)); |
| 7728 | +\end{codeblock} |
| 7729 | +\end{itemdescr} |
| 7730 | + |
| 7731 | +\indexlibraryglobal{println}% |
| 7732 | +\begin{itemdecl} |
| 7733 | +template<class... Args> |
| 7734 | + void println(@\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7735 | +\end{itemdecl} |
| 7736 | + |
| 7737 | +\begin{itemdescr} |
| 7738 | +\pnum |
| 7739 | +\effects |
| 7740 | +Equivalent to: |
| 7741 | +\begin{codeblock} |
| 7742 | +println(stdout, fmt, std::forward<Args>(args)...); |
| 7743 | +\end{codeblock} |
| 7744 | +\end{itemdescr} |
| 7745 | + |
| 7746 | +\indexlibraryglobal{println}% |
| 7747 | +\begin{itemdecl} |
| 7748 | +template<class... Args> |
| 7749 | + void println(FILE* stream, @\exposid{format-string}@<Args...> fmt, Args&&... args); |
| 7750 | +\end{itemdecl} |
| 7751 | + |
| 7752 | +\begin{itemdescr} |
| 7753 | +\pnum |
| 7754 | +\effects |
| 7755 | +Equivalent to: |
| 7756 | +\begin{codeblock} |
| 7757 | +print(stream, "{}\n", format(fmt, std::forward<Args>(args)...)); |
| 7758 | +\end{codeblock} |
| 7759 | +\end{itemdescr} |
| 7760 | + |
| 7761 | +\indexlibraryglobal{vprint_unicode}% |
| 7762 | +\begin{itemdecl} |
| 7763 | +void vprint_unicode(string_view fmt, format_args args); |
| 7764 | +\end{itemdecl} |
| 7765 | + |
| 7766 | +\begin{itemdescr} |
| 7767 | +\pnum |
| 7768 | +\effects |
| 7769 | +Equivalent to: |
| 7770 | +\begin{codeblock} |
| 7771 | +vprint_unicode(stdout, fmt, args); |
| 7772 | +\end{codeblock} |
| 7773 | +\end{itemdescr} |
| 7774 | + |
| 7775 | +\indexlibraryglobal{vprint_unicode}% |
| 7776 | +\begin{itemdecl} |
| 7777 | +void vprint_unicode(FILE* stream, string_view fmt, format_args args); |
| 7778 | +\end{itemdecl} |
| 7779 | + |
| 7780 | +\begin{itemdescr} |
| 7781 | +\pnum |
| 7782 | +\expects |
| 7783 | +\tcode{stream} is a valid pointer to an output C stream. |
| 7784 | + |
| 7785 | +\pnum |
| 7786 | +\effects |
| 7787 | +The function initializes an automatic variable via |
| 7788 | +\begin{codeblock} |
| 7789 | +string out = vformat(fmt, args); |
| 7790 | +\end{codeblock} |
| 7791 | +If \tcode{stream} refers to a terminal capable of displaying Unicode, |
| 7792 | +writes \tcode{out} to the terminal using the native Unicode API; |
| 7793 | +if \tcode{out} contains invalid code units, |
| 7794 | +\indextext{undefined}% |
| 7795 | +the behavior is undefined and |
| 7796 | +implementations are encouraged to diagnose it. |
| 7797 | +Otherwise writes \tcode{out} to \tcode{stream} unchanged. |
| 7798 | +\begin{note} |
| 7799 | +On POSIX and Windows, \tcode{stream} referring to a terminal means that, |
| 7800 | +respectively, |
| 7801 | +\tcode{isatty(fileno(\linebreak{}stream))} and |
| 7802 | +\tcode{GetConsoleMode(_get_osfhandle(_fileno(stream)), ...)} |
| 7803 | +return nonzero. |
| 7804 | +\end{note} |
| 7805 | +\begin{note} |
| 7806 | +On Windows, the native Unicode API is \tcode{WriteConsoleW}. |
| 7807 | +\end{note} |
| 7808 | + |
| 7809 | +\pnum |
| 7810 | +\throws |
| 7811 | +Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}. |
| 7812 | +\tcode{system_error} if writing to the terminal or \tcode{stream} fails. |
| 7813 | +May throw \tcode{bad_alloc}. |
| 7814 | + |
| 7815 | +\pnum |
| 7816 | +\recommended |
| 7817 | +If invoking the native Unicode API requires transcoding, |
| 7818 | +implementations should substitute invalid code units |
| 7819 | +with \unicode{fffd}{replacement character} per |
| 7820 | +The Unicode Standard Version 14.0 - Core Specification, Chapter 3.9. |
| 7821 | +\end{itemdescr} |
| 7822 | + |
| 7823 | +\indexlibraryglobal{vprint_nonunicode}% |
| 7824 | +\begin{itemdecl} |
| 7825 | +void vprint_nonunicode(string_view fmt, format_args args); |
| 7826 | +\end{itemdecl} |
| 7827 | + |
| 7828 | +\begin{itemdescr} |
| 7829 | +\pnum |
| 7830 | +\effects |
| 7831 | +Equivalent to: |
| 7832 | +\begin{codeblock} |
| 7833 | +vprint_nonunicode(stdout, fmt, args); |
| 7834 | +\end{codeblock} |
| 7835 | +\end{itemdescr} |
| 7836 | + |
| 7837 | +\indexlibraryglobal{vprint_nonunicode}% |
| 7838 | +\begin{itemdecl} |
| 7839 | +void vprint_nonunicode(FILE* stream, string_view fmt, format_args args); |
| 7840 | +\end{itemdecl} |
| 7841 | + |
| 7842 | +\begin{itemdescr} |
| 7843 | +\pnum |
| 7844 | +\expects |
| 7845 | +\tcode{stream} is a valid pointer to an output C stream. |
| 7846 | + |
| 7847 | +\pnum |
| 7848 | +\effects |
| 7849 | +Writes the result of \tcode{vformat(fmt, args)} to \tcode{stream}. |
| 7850 | + |
| 7851 | +\pnum |
| 7852 | +\throws |
| 7853 | +Any exception thrown by the call to \tcode{vformat}\iref{format.err.report}. |
| 7854 | +\tcode{system_error} if writing to \tcode{stream} fails. |
| 7855 | +May throw \tcode{bad_alloc}. |
| 7856 | +\end{itemdescr} |
| 7857 | + |
7576 | 7858 | \rSec1[string.streams]{String-based streams}
|
7577 | 7859 |
|
7578 | 7860 | \rSec2[sstream.syn]{Header \tcode{<sstream>} synopsis}
|
|
0 commit comments