ev-glaze-constexpr-string-rename-002¶
| 字段 | 值 |
|---|---|
| 项目 | stephenberry/glaze |
| 固定 commit | d78832c82289 |
| 路径 | include/glaze/util/key_transformers.hpp |
| 行段 | L249-L255 |
| 特性 | constexpr 中的动态分配 |
| 许可证 | MIT |
| 代码来源 | 项目源码 |
| 级别 | manual |
| 审核 | zyuhao7 @ 2026-10-27 |
| 测试代码 | 否 |
| 发现方式 | manual |
用法¶
用返回 std::string 的 constexpr 函数在编译期改写键名
为什么典型¶
键名重写在编译期完成,运行期只读取结果;库还用宏屏蔽不支持 constexpr string 的旧 ABI。
摘录¶
// Struct wrappers for inheritance-based usage
// These require constexpr std::string support (not available with _GLIBCXX_USE_CXX11_ABI=0)
#if GLZ_HAS_CONSTEXPR_STRING
struct camel_case
{
static constexpr std::string rename_key(const auto key) { return to_camel_case(key); }
};
备注¶
生产路径;结构体包装把 snake_case 到 camelCase 的转换暴露为静态成员函数。