|
1 | | -# Primitives 下一步实现计划清单(2026-03-23) |
| 1 | +# Primitives 下一步实现计划清单(2026-03-26) |
2 | 2 |
|
3 | 3 | ## 总体原则 |
4 | 4 |
|
5 | 5 | - [ ] 先定义稳定 API 边界,再落地实现 |
6 | 6 | - [ ] 每个能力都配套 tests + examples + docs |
7 | 7 | - [ ] 高风险转换默认禁止隐式触发,只允许显式 API |
| 8 | +- [ ] 明确分层职责:`algorithms` 负责值域/排序/边界元信息与值算法;`conversion` 负责显式类型变换 |
| 9 | +- [ ] 明确依赖方向:`conversion` 可依赖 `algorithms`,`algorithms` 不反向依赖 `conversion` |
8 | 10 |
|
9 | 11 | ## M1. C API 互操作层(双向) |
10 | 12 |
|
|
27 | 29 | ### 工作清单 |
28 | 30 |
|
29 | 31 | - [ ] 扩展 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(可比较性/可裁剪性/可转换性/是否有损/错误模型能力) |
32 | 41 | - [ ] 统一 `constexpr` 查询入口,减少分散 traits 访问 |
33 | 42 | - [ ] 增加编译期测试矩阵(`static_assert` 覆盖) |
34 | 43 |
|
35 | 44 | ### 验收标准 |
36 | 45 |
|
37 | 46 | - [ ] 上层模块仅依赖公开 concept/traits,不依赖 `details::*` |
38 | | -- [ ] 元信息可支撑转换层与算法层的约束判定 |
| 47 | +- [ ] `algorithms::traits` 可直接支撑算法层判定,并作为 conversion 的元信息依赖 |
| 48 | +- [ ] `std::numeric_limits` 相关逻辑不再散落在 `conversion`/`operations` 内部 |
39 | 49 |
|
40 | 50 | ## M3. 显式转换层(任意策略组适用) |
41 | 51 |
|
42 | 52 | ### 工作清单 |
43 | 53 |
|
44 | 54 | - [ ] 设计统一接口族(建议):`explicit_cast`、`try_cast`、`checked_cast` |
| 55 | +- [ ] 将边界、NaN、无穷大、精度与排序相关判定统一改为依赖 `algorithms::traits` / `algorithms::common_traits` |
45 | 56 | - [ ] 支持任意策略组组合,不绑定特定策略实现 |
46 | 57 | - [ ] 风险可见化(截断/溢出/精度损失)并可程序化读取 |
47 | 58 | - [ ] 定义失败语义(错误码或 expected 风格,按策略可配置) |
|
51 | 62 |
|
52 | 63 | - [ ] 所有跨类高风险转换必须走显式 API |
53 | 64 | - [ ] 风险信息可在编译期或运行期被确定性获取 |
| 65 | +- [ ] `conversion` 模块仅消费 `algorithms` 提供的元信息,不反向定义算法层协议 |
54 | 66 |
|
55 | | -## M4. 算法层(以 max/min 为起点) |
| 67 | +## M4. 算法层(traits 先行,以 max/min 为起点) |
56 | 68 |
|
57 | 69 | ### 工作清单 |
58 | 70 |
|
| 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 层 |
59 | 75 | - [ ] 实现 `max`/`min`,并预留 `clamp`/`compare` 扩展位 |
60 | | -- [ ] 算法统一依赖 M2+M3 的公开接口,不绕过转换层 |
61 | | -- [ ] 支持同类与受约束的异类输入 |
| 76 | +- [ ] 支持同类输入与受约束的异类输入;异类场景必须满足 `common_rep`、排序能力与策略组约束 |
| 77 | +- [ ] 明确 `partial_ordering` / `unordered` 语义,尤其是浮点 `NaN` 路径 |
| 78 | +- [ ] 为 `clamp`/`compare` 抽出复用内核:公共比较、边界判定、值选择 |
62 | 79 | - [ ] 在可行范围保持 `constexpr`/`noexcept` 特性 |
63 | | -- [ ] 增加边界测试(极值、NaN、有符号/无符号混合) |
| 80 | +- [ ] 增加边界测试(极值、NaN、有符号/无符号混合、不同 `comparison_category`) |
64 | 81 |
|
65 | 82 | ### 验收标准 |
66 | 83 |
|
67 | 84 | - [ ] 算法行为与策略约束一致 |
68 | 85 | - [ ] 风险路径始终显式、可审计 |
| 86 | +- [ ] `algorithms` 可独立编译并被 `conversion` 依赖,不形成反向模块耦合 |
| 87 | +- [ ] 算法层实现不通过“显式转换 API”间接完成值比较 |
69 | 88 |
|
70 | 89 | ## 建议推进顺序 |
71 | 90 |
|
72 | 91 | 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(建立跨语言边界,可按需求并行推进) |
76 | 96 |
|
77 | 97 | ## 总体完成跟踪 |
78 | 98 |
|
|
0 commit comments