Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Enhancement] Allow attributes, like format_read, to have inlined code

未关闭
#116 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
cpp
领域
compilers

调研方向

首先以当前和拟议的 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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WerWolv/PatternLanguage 的其他 Issue

查看 WerWolv/PatternLanguage 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。