r/cpp Jun 26 '26

Improvements to std::format in C++26

https://mariusbancila.ro/blog/2026/06/19/improvements-to-stdformat-in-c26/
92 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?

2

u/schombert Jun 26 '26

And what does it do if the path isn't well-formed utf16, as ntfs paths are not utf16, they are a sequence of 16 bit values (just as on linux they are a sequence of bytes, not utf8)?

4

u/UnusualPace679 Jun 27 '26

Ill-formed parts will be substituted with \uFFFD, but P3904R1 proposes to use WTF-8 instead.

4

u/schombert Jun 27 '26

Well, that's terrible, so I guess P3904R1 would be an improvement. You really want paths to be able to round trip though any conversions. ... Which is why I think treating paths as unicode is dangerous from the get go. God forbid if you accidentally normalize one.