Document Number: D3673R0
Date: 16.04.2025
Audience: Library Evolution Working Group Incubator (LEWGI, SG18), SG16
Author(s): Tymi <tymi.cpp@gmail.com>
Abstract
C++ introducedstd::print
/std::println
in C++23. While most functions support wide strings, this particular one lacks the support. This proposal aims to improve that by adding a collection of wide string compliant functions for it.std::wprint
andstd::wprintln
namely.
This proposal aims to improve the interface of the printing utilities by extending them with wide string versions.
That will allow for a better integration with systems using wide characters and programs preferring them.
C++23 has introduced std::print
and std::println
function templates, which allow for
easy and efficient text output to the console. They provide an interface for regular string formats. However,
they do not provide an interface for wide strings, which are commonly used in Windows systems, as well as in
specialised systems that work with non-standard encoding. I aim to improve that, by adding an interface to
make it accessible.
Implementing this proposal means adding new function templates to the standard library.
namespace std { template <typename... Args> void wprint(wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void wprint(FILE* stream, wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void wprintln(wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void wprintln();
template <typename... Args> void wprintln(FILE* stream, wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void wprintln(FILE* stream); }
These are the possible signatures for the functions covered by this proposal.
ECPPS has experimental support for std::wprint
/std::wprintln
via a language extension.
In an ideal world, the std::print
/std::println
functions would support overloads for
std::wformat_string
. Sadly they do not. An alternative approach to
std::wprint
/std::wprintln
would be to add such overloads. However, I find it
inconsistent with other library features such as std::(w)cout
, std::(w)string
,
std::(w)format_string
itself etc. Except for few rare cases (such as std::format
function template), std::wmeow
is the standard preferred version.
There could also exist std::u8print
, std::u16print
, std::u32print
functions, but this revision does not include them. Maybe in further revisions or another proposal.
Here are a couple of examples where std::wprint
/std::wprintln
could be benefitial.
int main(void) { std::wstring locale{}; locale.resize(LOCALE_NAME_MAX_LENGTH); locale.resize(GetUserDefaultLocaleName(locale.data(), locale.size()) - 1); std::wprintln(L"The System Locale is {}", locale); }
Expected output:
The System Locale is en-GB