Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- Articles with code examples that doesn't show their output are just silly. This one deals with `std::println` to print pointer formatting with no output.by arunc
- > This makes it possible to use static_assert for instance with std::format...
This is great but it sounds like it doesn't work for floats yet
> For now, compile-time std::format covers integers, strings, and diagnostics well, with floating-point support waiting on a separate paper (P3652) to make the floating-point <charconv> functions constexpr.
by randusername - I am working on it. Floating-point IO is rather heavyweight, so the usual approach of naively slapping constexpr on all the things and putting them in headers can have some observable negative consequences on resource usage during compilation even if you don't use the new constexpr functionality.
To the best of my knowledge fmtlib does implement constexpr formatting for float and double, but not long double.
by leni536 - > 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...).
by Longhanks - > Ill-formed UTF-16 is replaced with U+FFFD by default, or escaped under {:?}.
Silently corrupting the path seems an odd choice in this day and age, when WTF8 has existed for many years and fixes this round trip bug / security vulnerability
by manwe150 - I'm more happy to see C++ moving to consolidate around a single formatting model.
This past year we were porting Elemental (PC game) to 64-bit so it's pretty old code. There are a gazillion different string types in it (sprintf and beyond).
by draginol - Surely std::print() shouldn't print anything?by veltas
- I think it is a typo, and should be std::println()by steeleduncan
- Why even call it in that case?by nikbackm
- It's a typo, he describes it as std::println in the text, but the code snippet is just print()