[Enhancement] Allow attributes, like format_read, to have inlined code
还没有人认领这个 Issue。
评估
调研方向
首先以当前和拟议的 DATE 示例作为行为参考,追踪 format_read 和 transform 属性是如何被解析和应用的。确定内联表达式如何接收 struct 字段,以及现有的具名函数如何继续获得支持;完成的标准是两种形式都能工作,而不需要名称唯一的辅助函数。
由索引模型根据 Issue 内容生成。
描述
Currently, various attributes like format_read require a string containing a function name as the argument. A lot of the time, these functions seem to end up being a simple one-liner.
// == current ==
struct DATE
{
u16 year;
u8 month;
u8 day;
}
[[
format_read("read_DATE"),
transform("transform_DATE"),
...
]];
fn read_DATE(auto v)
{
return std::format("{}-{}-{}", v.year, v.month, v.day);
};
fn transform_DATE(auto v)
{
return (v.year * 10000) + (v.month * 100) + v.day;
};
This adds a decent amount of boilerplate overhead, making the underlying data format specification a little more difficult to read (due to tool integration 'noise'). Although the function could be moved to a different part of the pattern file, to somewhat separate data format from integration, the function would then no longer be co-located with the data it's operating on.
I feel things could be cleaner / clearer, if the contents of that function were optionally able to be inlined. This also avoids needing the pattern creator to make sure the function is uniquely named, as well as having to access the data through a (named) parameter.
As a first pass suggestion, inlining simple one-liners could look like:
// == proposed ==
struct DATE
{
u16 year;
u8 month;
u8 day;
}
[[
format_read(std::format("{}-{}-{}", year, month, day)),
transform((year * 10000) + (month * 100) + day),
...
]];
- 主要语言
- C++
- 星标
- 275
- 派生
- 75
- 平均合并
- 1 天 22 小时
- 30 天内合并 PR
- 10
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
WerWolv/PatternLanguage 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 48/100
WerWolv/PatternLanguage#236 · 12 条评论 ·
-
难度 5/5 一周以上 新手友好度 35/100
WerWolv/PatternLanguage#226 · 3 条评论 ·
-
难度 3/5 1-2 天 新手友好度 45/100
WerWolv/PatternLanguage#221 · 4 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
WerWolv/PatternLanguage#219 ·
-
难度 3/5 1-2 天 新手友好度 48/100
WerWolv/PatternLanguage#218 ·
查看 WerWolv/PatternLanguage 的全部 Issue
相似的 Issue
-
bug build
难度 1/5 1 小时以内 新手友好度 91/100
facebookincubator/velox#19194 ·
-
JIT-compiled number -> Decimal conversion silently overflows instead of raising DECIMAL_OVERFLOW 未关闭fuzz
难度 2/5 1-3 小时 新手友好度 82/100
ClickHouse/ClickHouse#122114 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
-
module/agent platform/macos type/bug/regression
难度 2/5 1-3 小时 新手友好度 88/100
-
enhancement PyCDE
难度 2/5 1-3 小时 新手友好度 78/100