Improvements to Std:Format in C++26
21 points
2 days ago
| 2 comments
| mariusbancila.ro
| HN
Longhanks
1 hour ago
[-]
> A related issue solved along was Windows string representation of paths. std::filesystem::path stores its text in wchar_t encoded as UTF-16 (Windows native). But p.string() narrows it down to the active code page, rather than UTF-8 which is what the formatting library expects. The result was a non-ASCII path could get transcoded to gibberish. The C++26 std::formatter<std::filesystem::path> converts Windows native UTC-16 to UTF-8 using Unicode transcoding and avoiding code pages, therefore solving the problem.

...only to then convert it back to UTF-16 for WriteConsoleW(), which std::print() usually calls (unless not running in a console) (https://github.com/microsoft/STL/blob/488e7953685722d2d6666f...).

reply
veltas
1 hour ago
[-]
Surely std::print() shouldn't print anything?
reply
CamouflagedKiwi
1 hour ago
[-]
It's a typo, he describes it as std::println in the text, but the code snippet is just print()
reply
steeleduncan
1 hour ago
[-]
I think it is a typo, and should be std::println()
reply
nikbackm
1 hour ago
[-]
Why even call it in that case?
reply
IshKebab
8 minutes ago
[-]
Typo in this case, but in general supporting "useless" code like this is sometimes a good idea because it makes writing generic code easier. Maybe not in this case.
reply
xuhu
1 hour ago
[-]
It's apparently a typo in the article, they probably meant to write `println()`.
reply