ev-spdlog-structured-bindings-to-chars-002¶
| 字段 | 值 |
|---|---|
| 项目 | gabime/spdlog |
| 固定 commit | 79524ddd08a4 |
| 路径 | include/spdlog/details/fmt_helper.h |
| 行段 | L33-L38 |
| 特性 | 结构化绑定 |
| 许可证 | MIT |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-25 |
| 测试代码 | 否 |
| 发现方式 | tree-sitter |
用法¶
把 to_chars 返回的指针与错误码绑定为具名变量
为什么典型¶
to_chars 返回 pair
摘录¶
auto [ptr, ec] = std::to_chars(buf, buf + BUF_SIZE, n, 10);
if (ec == std::errc()) {
dest.append(buf, ptr);
} else {
throw_spdlog_ex("Failed to format int", static_cast<int>(ec));
}
备注¶
生产路径;该实现只在 SPDLOG_USE_STD_FORMAT 下启用。