Skip to content

Commit e33c615

Browse files
refactor: Update implementation plan with clear responsibilities and dependencies for algorithms and conversion layers
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
1 parent a74666e commit e33c615

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

.agents/docs/plans/implementation-plan.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Primitives 下一步实现计划清单(2026-03-23
1+
# Primitives 下一步实现计划清单(2026-03-26
22

33
## 总体原则
44

55
- [ ] 先定义稳定 API 边界,再落地实现
66
- [ ] 每个能力都配套 tests + examples + docs
77
- [ ] 高风险转换默认禁止隐式触发,只允许显式 API
8+
- [ ] 明确分层职责:`algorithms` 负责值域/排序/边界元信息与值算法;`conversion` 负责显式类型变换
9+
- [ ] 明确依赖方向:`conversion` 可依赖 `algorithms``algorithms` 不反向依赖 `conversion`
810

911
## M1. C API 互操作层(双向)
1012

@@ -27,21 +29,30 @@
2729
### 工作清单
2830

2931
- [ ] 扩展 concept 分层(category/representation/policy-capability)
30-
- [ ] 完善 `traits<T>` 元信息(`kind``rep_type`、limits、policy tags)
31-
- [ ] 提供检测类 API(可转换性/是否有损/错误模型能力)
32+
- [ ] 明确 `underlying::traits<T>``algorithms::traits<T>` 的职责边界:前者描述表示层;后者描述值算法层
33+
- [ ] 完善 `traits<T>` 元信息(`kind``rep_type`、policy tags)
34+
- [ ] 设计 `algorithms::traits<T>`,内容参考 `std::numeric_limits`,但只保留算法/比较所需子集:
35+
- [ ] `min()` / `lowest()` / `max()` / `epsilon()` / `infinity()` / `quiet_nan()`
36+
- [ ] `is_bounded` / `is_exact` / `is_signed` / `is_integer` / `is_iec559`
37+
- [ ] `has_infinity` / `has_quiet_nan` / `digits` / `digits10` / `radix`
38+
- [ ] 增加排序能力元信息:`comparison_category``totally_ordered``partially_ordered``unordered_possible`
39+
- [ ] 提供双参聚合元信息:`algorithms::common_traits<Lhs, Rhs>`,统一暴露 `common_rep`、可比较性、边界查询与策略兼容性
40+
- [ ] 提供检测类 API(可比较性/可裁剪性/可转换性/是否有损/错误模型能力)
3241
- [ ] 统一 `constexpr` 查询入口,减少分散 traits 访问
3342
- [ ] 增加编译期测试矩阵(`static_assert` 覆盖)
3443

3544
### 验收标准
3645

3746
- [ ] 上层模块仅依赖公开 concept/traits,不依赖 `details::*`
38-
- [ ] 元信息可支撑转换层与算法层的约束判定
47+
- [ ] `algorithms::traits` 可直接支撑算法层判定,并作为 conversion 的元信息依赖
48+
- [ ] `std::numeric_limits` 相关逻辑不再散落在 `conversion`/`operations` 内部
3949

4050
## M3. 显式转换层(任意策略组适用)
4151

4252
### 工作清单
4353

4454
- [ ] 设计统一接口族(建议):`explicit_cast``try_cast``checked_cast`
55+
- [ ] 将边界、NaN、无穷大、精度与排序相关判定统一改为依赖 `algorithms::traits` / `algorithms::common_traits`
4556
- [ ] 支持任意策略组组合,不绑定特定策略实现
4657
- [ ] 风险可见化(截断/溢出/精度损失)并可程序化读取
4758
- [ ] 定义失败语义(错误码或 expected 风格,按策略可配置)
@@ -51,28 +62,37 @@
5162

5263
- [ ] 所有跨类高风险转换必须走显式 API
5364
- [ ] 风险信息可在编译期或运行期被确定性获取
65+
- [ ] `conversion` 模块仅消费 `algorithms` 提供的元信息,不反向定义算法层协议
5466

55-
## M4. 算法层(以 max/min 为起点)
67+
## M4. 算法层(traits 先行,以 max/min 为起点)
5668

5769
### 工作清单
5870

71+
- [ ] 确定模块结构:`mcpplibs.primitives.algorithms``mcpplibs.primitives.algorithms.traits``mcpplibs.primitives.algorithms.compare``mcpplibs.primitives.algorithms.minmax`
72+
- [ ] 先实现 `algorithms::traits``algorithms::common_traits`,作为整个算法层与 conversion 的基础依赖
73+
- [ ] 约束算法职责只涉及值的比较、选择、裁剪与边界处理,不提供目标类型导向的 cast API
74+
- [ ] `max`/`min` 内部仅允许做 `common_rep` 归一化或排序语义协商,不绕回 conversion 层
5975
- [ ] 实现 `max`/`min`,并预留 `clamp`/`compare` 扩展位
60-
- [ ] 算法统一依赖 M2+M3 的公开接口,不绕过转换层
61-
- [ ] 支持同类与受约束的异类输入
76+
- [ ] 支持同类输入与受约束的异类输入;异类场景必须满足 `common_rep`、排序能力与策略组约束
77+
- [ ] 明确 `partial_ordering` / `unordered` 语义,尤其是浮点 `NaN` 路径
78+
- [ ]`clamp`/`compare` 抽出复用内核:公共比较、边界判定、值选择
6279
- [ ] 在可行范围保持 `constexpr`/`noexcept` 特性
63-
- [ ] 增加边界测试(极值、NaN、有符号/无符号混合)
80+
- [ ] 增加边界测试(极值、NaN、有符号/无符号混合、不同 `comparison_category`
6481

6582
### 验收标准
6683

6784
- [ ] 算法行为与策略约束一致
6885
- [ ] 风险路径始终显式、可审计
86+
- [ ] `algorithms` 可独立编译并被 `conversion` 依赖,不形成反向模块耦合
87+
- [ ] 算法层实现不通过“显式转换 API”间接完成值比较
6988

7089
## 建议推进顺序
7190

7291
1. M2(先夯实约束与元信息基础)
73-
2. M1(建立跨语言边界)
74-
3. M3(收敛转换风险)
75-
4. M4(复用基础能力实现算法)
92+
2. M4 前半:`algorithms::traits` / `common_traits` / 排序能力查询
93+
3. M3(让 conversion 改为依赖 algorithms 元信息)
94+
4. M4 后半:`max` / `min` / `clamp` / `compare`
95+
5. M1(建立跨语言边界,可按需求并行推进)
7696

7797
## 总体完成跟踪
7898

0 commit comments

Comments
 (0)