ev-fmt-fold-named-arg-002¶
| 字段 | 值 |
|---|---|
| 项目 | fmtlib/fmt |
| 固定 commit | 1be298e1bd68 |
| 路径 | include/fmt/compile.h |
| 行段 | L209-L216 |
| 特性 | 折叠表达式 |
| 许可证 | MIT |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-25 |
| 测试代码 | 否 |
| 发现方式 | tree-sitter |
用法¶
用逻辑或折叠在参数包中查找匹配的命名格式参数
为什么典型¶
try_format_argument 对每个参数返回 bool;(call || ...) 在任一匹配时短路,空参数包得到 false 并进入统一的 format_error 分支,不需要额外的递归终止重载。
摘录¶
template <typename OutputIt, typename... T>
constexpr auto format(OutputIt out, const T&... args) const -> OutputIt {
bool found = (try_format_argument(out, name, args) || ...);
if (!found) {
FMT_THROW(format_error("argument with specified name is not found"));
}
return out;
}
备注¶
生产路径;位于 constexpr 编译期格式串实现,逻辑或折叠直接产生是否找到参数的布尔结果。