Document Number: D3673R0
Date: 16.04.2025
Audience: Library Evolution Working Group Incubator (LEWGI, SG18), SG16
Author(s): Tymi <[email protected]>
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 overloads functions for it, acceptingstd::wformat_string
.
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 overloads for a function template to the standard library.
namespace std { template <typename... Args> void print(wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void print(FILE* stream, wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void println(wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void println();
template <typename... Args> void println(FILE* stream, wformat_string<Args...> fmt, Args&&... args);
template <typename... Args> void println(FILE* stream); }
These are the possible signatures for the functions covered by this proposal.
No implementation experience yet, although there is a work in progress project to add those overloads into MSVC, clang and ECPPS.
Some might say adding a separate function for wide string support such as wprint/wprintln would align more with other functions such as printf, cout, etc. Although in my opinion these names are remaments of C, and std::print
is closer to std::format
which uses the overload convention.
There could also exist overloads for other strings (std::basic_format_string >charN_t<
), but this proposal does not cover those. Maybe in a future revision or a separate paper.
Here are a couple of examples where std::print
/std::println
wide string overloads could be benefitial.
int main(void) { std::wstring locale{}; locale.resize(LOCALE_NAME_MAX_LENGTH); locale.resize(GetUserDefaultLocaleName(locale.data(), locale.size()) - 1); std::println(L"The System Locale is {}", locale); }
Expected output:
The System Locale is en-GB
void PrintPath(std::filesystem::path path) { std::println(L"Path = {}", path); }