11# mcpplibs primitives
22
3- > C++23 模块化原语库 - ` import mcpplibs.primitives; `
3+ > C++23 模块化 primitives 库 - ` import mcpplibs.primitives; `
44
55[ ![ d2x] ( https://img.shields.io/badge/d2x-ok-green.svg )] ( https://github.com/d2learn/d2x )
66[ ![ Online-ebook] ( https://img.shields.io/badge/online-ebook-orange.svg )] ( https://github.com/d2learn/d2x )
77[ ![ License] ( https://img.shields.io/badge/license-Apache_2.0-blue.svg )] ( LICENSE-CODE )
88
99| [ 中文] ( README.zh.md ) - [ English] ( README.md ) - [ 论坛] ( https://mcpp.d2learn.org/forum ) |
1010| ----------------------------------------------------------------------------------|
11- | [ 用户文档] ( docs/guide/zh/README.md ) - [ User Documentation] ( docs/guide/en/README.md ) |
12- | [ API文档] ( docs/guide/ api/README.md ) - [ API Documentation] ( docs/api/en/README.md ) |
11+ | [ 用户文档] ( docs/guide/zh/README.md ) - [ User Documentation] ( docs/guide/en/README.md ) |
12+ | [ API文档] ( docs/api/zh/ README.md ) - [ API Documentation] ( docs/api/en/README.md ) |
1313
14- 本仓库提供可配置的 ` primitive ` 基础设施(` underlying traits ` 、` policy ` 、` operations/dispatcher ` ),用于统一约束数值计算 、错误处理与并发访问语义。
14+ 本仓库提供可配置的 ` primitive ` 基础设施(` underlying traits ` 、` policy ` 、` operations/dispatcher ` ),用于统一数值行为 、错误处理与并发访问语义。
1515
1616> [ !WARNING]
17- > 当前项目仍在快速演进中 ,API 可能发生变更 。
17+ > 项目仍在快速演进中 ,API 可能继续调整 。
1818
1919## 特性
2020
21- - ** C++23 模块** — ` import mcpplibs.primitives; `
22- - ** 双构建系统** — 同时支持 xmake 和 CMake
23- - ** 策略驱动行为** — 值/类型/错误/并发策略可组合配置
24- - ** 混合运算支持** — 支持 ` primitive ` 与 ` underlying ` 的混合二元运算
25- - ** 并发访问接口** — ` primitive::load/store/compare_exchange `
21+ - ** C++23 模块** : ` import mcpplibs.primitives; `
22+ - ** 双构建系统** : 同时支持 xmake 和 CMake
23+ - ** 策略驱动行为** : value/type/error/concurrency 策略可组合配置
24+ - ** 混合运算支持** : 支持 ` primitive ` 与 ` underlying ` 的二元运算
25+ - ** 并发访问接口** : ` primitive::load/store/compare_exchange `
2626
2727## Operators
2828
29- 该库为 ` primitive ` 提供了常见的一元 、算术、位运算与比较操作。
30- 算术结果通过统一分发链路返回 ` std::expected<..., policy::error::kind> ` 。
29+ 该库为 ` primitive ` 提供常见的一元 、算术、位运算和比较操作。
30+ 算术路径通过统一分发链路返回 ` std::expected<..., policy::error::kind> ` 。
3131
32- - 值策略(` policy::value::checked ` / ` policy::value::saturating ` / ` policy::value::unchecked ` )决定溢出行为;
33- - 错误策略(` policy::error::throwing ` / ` policy::error::expected ` / ` policy::error::terminate ` )决定错误传播方式 。
32+ - 值策略(` policy::value::checked ` / ` policy::value::saturating ` / ` policy::value::unchecked ` )定义溢出行为。
33+ - 错误策略(` policy::error::throwing ` / ` policy::error::expected ` / ` policy::error::terminate ` )定义错误传播方式 。
3434
3535示例:
3636
@@ -53,24 +53,24 @@ auto maybe_overflow =
5353
5454## Policy 协议命名空间
5555
56- 自定义 policy 时,协议入口按职责拆分到子命名空间 :
56+ 实现自定义 policy 时,协议入口按职责拆分为以下命名空间 :
5757
5858- `policy::type::handler` / `policy::type::handler_available`
5959- `policy::concurrency::handler` / `policy::concurrency::injection`
6060- `policy::value::handler` / `policy::value::decision`
6161- `policy::error::handler` / `policy::error::request` / `policy::error::kind`
6262
63- 预设 policy 标签:
63+ 内置 policy 标签:
6464
6565- `policy::value::{checked, unchecked, saturating}`
6666- `policy::type::{strict, compatible, transparent}`
6767- `policy::error::{throwing, expected, terminate}`
6868- `policy::concurrency::{none, fenced, fenced_relaxed, fenced_acq_rel, fenced_seq_cst}`
6969
70- 并发策略说明 :
70+ 并发说明 :
7171
72- - `fenced*` 系列是操作级并发语义,通过策略注入内存序 fence;
73- - `primitive` 存储仍保持统一、零额外存储抽象;
72+ - `fenced*` 系列提供操作级并发语义,并通过策略注入内存序 fence。
73+ - `primitive` 存储保持统一的零额外存储抽象。
7474- `primitive::load/store/compare_exchange` 由并发策略协议提供,若策略未实现会在编译期报错。
7575
7676示例(并发访问 API):
@@ -98,16 +98,16 @@ if (v.compare_exchange(expected, 3)) {
9898
9999## 示例程序
100100
101- - ` ex01_basic_usage ` : 演示 literal 与 primitive 工厂函数联合使用,并覆盖更多内置操作符。
102- - ` ex02_type_policy ` : 展示 ` strict/compatible ` 的类型协商差异,并包含 ` underlying ` 构造路径对 type 策略的影响。
103- - ` ex03_value_policy ` : 展示 ` checked/unchecked/saturating ` ,并包含与 ` underlying ` 的混合二元运算行为 。
104- - ` ex04_error_policy ` : 展示不同 error 策略的处理方式 。
105- - ` ex05_concurrency_policy ` : 读写组合并发场景 (writer ` store ` + reader ` add/sub ` + ` CAS ` )示例 。
106- - ` ex06_conversion ` : 展示 underlying 与 primitive 之间的 checked/saturating/truncating/exact 转换 。
107- - ` ex07_algorithms ` : 展示 limits、特殊数值与 hash 等 algorithms 辅助接口 。
108- - ` ex08_custom_underlying ` : 自定义 underlying traits、rep 校验与 common rep 扩展。
109- - ` ex09_custom_policy ` : 自定义策略协议实现示例 。
110- - ` ex10_custom_operation ` : 自定义 operation 扩展示例 。
101+ - ` ex01_basic_usage ` : 展示 literal 与 primitive 工厂函数联合使用,并覆盖更多内置操作符。
102+ - ` ex02_type_policy ` : 展示 ` strict/compatible ` 的类型协商差异,以及 ` underlying ` 构造对 type 策略的影响。
103+ - ` ex03_value_policy ` : 展示 ` checked/unchecked/saturating ` 行为,以及与 ` underlying ` 的混合二元运算 。
104+ - ` ex04_error_policy ` : 展示不同 error 策略下的错误处理方式 。
105+ - ` ex05_concurrency_policy ` : 展示典型的读写混合并发场景 (writer ` store ` + reader ` add/sub ` + ` CAS ` )。
106+ - ` ex06_conversion ` : 展示 underlying 与 primitive 之间的 ` checked/saturating/truncating/exact ` 转换辅助接口 。
107+ - ` ex07_algorithms ` : 展示 limits 元信息、特殊数值和哈希辅助接口 。
108+ - ` ex08_custom_underlying ` : 展示自定义 underlying traits、rep 校验和 common rep 扩展。
109+ - ` ex09_custom_policy ` : 展示自定义 policy 协议实现 。
110+ - ` ex10_custom_operation ` : 展示自定义 operation 扩展 。
111111
112112## 项目结构
113113
@@ -120,7 +120,7 @@ mcpplibs-primitives/
120120│ ├── operations/ # operation tags / dispatcher / operators
121121│ └── underlying/ # underlying traits 与 common_rep
122122├── examples/ # 示例程序
123- ├── tests/ # 测试入口与 basic 测试集
123+ ├── tests/ # 测试入口与基础测试集
124124├── xmake.lua # xmake 构建脚本
125125├── CMakeLists.txt # CMake 构建脚本
126126└── .xlings.json # xlings 包描述文件
@@ -153,15 +153,15 @@ xlings install
153153
154154``` bash
155155xmake build mcpplibs-primitives
156- xmake run basic # 等价于 ex01_basic_usage
156+ xmake run basic # ex01_basic_usage 的兼容别名
157157xmake run ex01_basic_usage
158158xmake run ex06_conversion
159159xmake run ex07_algorithms
160160xmake run ex05_concurrency_policy
161161xmake run primitives_test
162162```
163163
164- ** 使用 CMake**
164+ ** 使用 CMake** ( ` CMake >= 3.31 ` )
165165
166166``` bash
167167cmake -B build -G Ninja
@@ -192,8 +192,8 @@ target("myapp")
192192
193193## 相关链接
194194
195- - [ mcpp-style-ref | 现代 C++ 编码/项目风格参考 ] ( https://github.com/mcpp-community/mcpp-style-ref )
196- - [ d2mystl | 从零实现一个迷你STL库 ] ( https://github.com/mcpp-community/d2mystl )
197- - [ mcpp 社区官网 ] ( https://mcpp.d2learn.org )
198- - [ mcpp | 现代 C++ 爱好者论坛 ] ( https://mcpp.d2learn.org/forum )
199- - [ 入门教程: 动手学现代 C++] ( https://github.com/Sunrisepeak/mcpp-standard )
195+ - [ mcpp-style-ref | 现代 C++ 编码与项目风格参考 ] ( https://github.com/mcpp-community/mcpp-style-ref )
196+ - [ d2mystl | 从零实现一个迷你 STL ] ( https://github.com/mcpp-community/d2mystl )
197+ - [ mcpp 社区网站 ] ( https://mcpp.d2learn.org )
198+ - [ mcpp 论坛 ] ( https://mcpp.d2learn.org/forum )
199+ - [ 入门教程:动手学习现代 C++] ( https://github.com/Sunrisepeak/mcpp-standard )
0 commit comments