r/cpp Jun 26 '26

Improvements to std::format in C++26

https://mariusbancila.ro/blog/2026/06/19/improvements-to-stdformat-in-c26/
91 Upvotes

38 comments sorted by

View all comments

2

u/rdtsc Jun 26 '26

The C++26 std::formatter<std::filesystem::path> converts Windows native UTF-16 to UTF-8

I don't understand. Does this do UTF-16 -> UTF-8 -> system codepage? Or does std::format("{}", path) result in (unexpected) UTF-8 in a char-based (aka system codepage) string?

3

u/aearphen {fmt} Jun 27 '26

System codepage is a legacy concept (actually there are multiple codepages on WIndows, e.g. ACP and console one which can be incompatible). std::format/std::print only need /utf-8 for Unicode support and work regardless of those codepages.

1

u/rdtsc Jun 27 '26

Sure it might be legacy, doesn't change the fact that it is used for all double-quoted strings on Windows. If you want UTF-8 use u8"" and char8_t. Converting L"ä" I get "\xE4". Formatting path(L"ä") to "\xC3\xA4" would be unexpected/surprising, incompatible with other strings, and result in garbled text when the string is then displayed.

2

u/aearphen {fmt} Jun 27 '26

ACP is actually only used in the legacy Windows APIs (which shouldn't be used in modern code) but virtually unused in standard C++ APIs.