ev-fmt-filesystem-path-helper-001¶
| 字段 | 值 |
|---|---|
| 项目 | fmtlib/fmt |
| 固定 commit | 1be298e1bd68 |
| 路径 | include/fmt/std.h |
| 行段 | L102-L111 |
| 特性 | std::filesystem |
| 许可证 | MIT |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-24 |
| 测试代码 | 否 |
| 发现方式 | tree-sitter |
用法¶
从 path 取出指定字符类型的原生字符串
为什么典型¶
把 filesystem::path 当作可查询对象,按目标字符类型选择窄字符串或 UTF-8 转换,是库适配标准类型的常见写法。
摘录¶
template <typename Char, typename PathChar>
auto get_path_string(const std::filesystem::path& p,
const std::basic_string<PathChar>& native) {
if constexpr (std::is_same_v<Char, char> &&
std::is_same_v<PathChar, wchar_t>) {
return to_utf8<wchar_t>(native, to_utf8_error_policy::wtf);
} else {
return p.string<Char>();
}
}
备注¶
生产路径;固定 commit 已由 tools/validate.py --check-corpus 校验。