跳转至

ev-fmt-byte-formatter-001

字段 值
项目 fmtlib/fmt
固定 commit 1be298e1bd68
路径 include/fmt/std.h
行段 L690-L702
特性 std::byte
许可证 MIT
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-24
测试代码 否
发现方式 regex

用法

为 std::byte 提供格式化器

为什么典型

标准类型没有流运算符时,在库边界通过 format_as 转成整数并复用现有格式化路径。

摘录

#ifdef __cpp_lib_byte
template <typename Char>
struct formatter<std::byte, Char> : formatter<unsigned, Char> {
  FMT_CONSTEXPR static auto format_as(std::byte b) -> unsigned char {
    return static_cast<unsigned char>(b);
  }
  template <typename Context>
  FMT_CONSTEXPR auto format(std::byte b, Context& ctx) const
      -> decltype(ctx.out()) {
    return formatter<unsigned, Char>::format(format_as(b), ctx);
  }
};
#endif

备注

生产路径;由 __cpp_lib_byte 特性检测保护。

查看固定 commit 源码 · 返回证据索引