Skip to content

Conversation

@mazunki
Copy link
Contributor

@mazunki mazunki commented Oct 28, 2025

As requested in #2309 (comment), byte-formatters now reside in a standalone namespace.

I have also introduced a stringifier for errno values. The standard has strerror() for the corresponding message, but not the name. This provides errno_name(errno) for this purpose.

There's also a convenience helper for things that don't support string-views: errno_cstr(errno). This is preferred over explicitly doing errno_name(errno).data() in corresponding locations because this way we can eventually deprecate c-strings from a single location without having to track down who uses printf-style specifiers.

Sadly, there is no convenient way to put these into an enum class and have the compiler turn it into a string. There are hopes for this in C++26, see: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2996r13.html

@mazunki mazunki changed the title Introduce utils::format Introduce util::format Oct 28, 2025
@MagnusS MagnusS requested a review from alfreb October 29, 2025 08:53
@mazunki
Copy link
Contributor Author

mazunki commented Oct 29, 2025

Actually, we have api/utils/units.hpp, which I had forgot someone mentioned. While Byte_r is alright, it doesn't provide std::formatter<Byte_r> which is desired for std::format().

There are currently two different ways to represent bytes, this PR doesn't change that; none of which are friendly to formatting.

For what it's worth, we might want to introduce Errno(n) for the same purpose, so we can have std::formatter<Errno> too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant