aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-21 23:09:14 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-04-17 17:33:10 +0100
commit7c2a9dbcc2c1cb1563774068c59d5e09edc59f06 (patch)
tree94a222b3a64132f9065a47bf50407a4e0c40e0b2 /libstdc++-v3/include
parent57056146f4ffc5ea347c03e37e1e2c7cd99261d0 (diff)
downloadgcc-7c2a9dbcc2c1cb1563774068c59d5e09edc59f06.zip
gcc-7c2a9dbcc2c1cb1563774068c59d5e09edc59f06.tar.gz
gcc-7c2a9dbcc2c1cb1563774068c59d5e09edc59f06.tar.bz2
libstdc++: Implement "Printing blank lines with println" for C++23
This was recently approved for C++26 at the Tokyo meeting. As suggested by Stephan T. Lavavej, I'm defining it as an extension for C++23 mode (when std::print and std::prinln were first added) rather than as a new C++26 feature. Both MSVC and libc++ have agreed to do this too. libstdc++-v3/ChangeLog: * include/std/ostream (println(ostream&)): Define new overload. * include/std/print (println(FILE*), println()): Likewise. * testsuite/27_io/basic_ostream/print/2.cc: New test. * testsuite/27_io/print/1.cc: Remove unused header. * testsuite/27_io/print/3.cc: New test.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/std/ostream12
-rw-r--r--libstdc++-v3/include/std/print14
2 files changed, 26 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index a136399..8a21758 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -995,6 +995,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::print(__os, "{}\n",
std::format(__fmt, std::forward<_Args>(__args)...));
}
+
+ // Defined for C++26, supported as an extension to C++23.
+ inline void println(ostream& __os)
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if constexpr (__unicode::__literal_encoding_is_utf8())
+ std::vprint_unicode(__os, "\n", std::make_format_args());
+ else
+#endif
+ __os.put('\n');
+ }
+
#endif // __cpp_lib_print
#endif // C++11
diff --git a/libstdc++-v3/include/std/print b/libstdc++-v3/include/std/print
index d440334..0c259d0 100644
--- a/libstdc++-v3/include/std/print
+++ b/libstdc++-v3/include/std/print
@@ -136,6 +136,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
vprint_nonunicode(string_view __fmt, format_args __args)
{ std::vprint_nonunicode(stdout, __fmt, __args); }
+ // Defined for C++26, supported as an extension to C++23.
+ inline void println(FILE* __stream)
+ {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ if constexpr (__unicode::__literal_encoding_is_utf8())
+ std::vprint_unicode(__stream, "\n", std::make_format_args());
+ else
+#endif
+ if (std::putc('\n', __stream) == EOF)
+ __throw_system_error(EIO);
+ }
+
+ inline void println() { std::println(stdout); }
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __cpp_lib_print