Skip to content

Commit 490c869

Browse files
refactor: Update example references and commands for clarity and consistency
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
1 parent 92f4bba commit 490c869

8 files changed

Lines changed: 68 additions & 42 deletions

File tree

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ Default policies are available under `policy::defaults`:
9898

9999
## Examples
100100

101-
- `ex01_default_arithmetic`: Basic arithmetic under default policies.
101+
- `ex01_basic_usage`: Literals + primitive factory helpers with the built-in operator set.
102102
- `ex02_type_policy`: Type negotiation with `strict/compatible`, including how type policy affects construction from `underlying`.
103103
- `ex03_value_policy`: `checked/unchecked/saturating` behavior, including mixed binary operations with `underlying`.
104104
- `ex04_error_policy`: Error-handling behavior across different error policies.
105105
- `ex05_concurrency_policy`: Representative mixed read/write concurrency workload (writer `store` + reader `add/sub` + `CAS`).
106-
- `ex06_custom_underlying`: Custom underlying traits, rep validation, and common-rep extension.
107-
- `ex07_custom_policy`: Custom policy protocol implementation.
108-
- `ex08_custom_operation`: Custom operation extension.
106+
- `ex06_conversion`: Checked/saturating/truncating/exact conversion helpers across underlying values and primitives.
107+
- `ex07_algorithms`: Limits metadata, special numeric values, and hashing helpers.
108+
- `ex08_custom_underlying`: Custom underlying traits, rep validation, and common-rep extension.
109+
- `ex09_custom_policy`: Custom policy protocol implementation.
110+
- `ex10_custom_operation`: Custom operation extension.
109111

110112
## Project Layout
111113

@@ -117,7 +119,7 @@ mcpplibs-primitives/
117119
│ ├── policy/ # policy tags and protocol implementations
118120
│ ├── operations/ # operation tags / dispatcher / operators
119121
│ └── underlying/ # underlying traits and common_rep
120-
├── examples/ # ex01 ~ ex08 examples
122+
├── examples/ # example programs
121123
├── tests/ # test entry and basic test suite
122124
├── xmake.lua # xmake build script
123125
├── CMakeLists.txt # CMake build script
@@ -151,7 +153,10 @@ xlings install
151153

152154
```bash
153155
xmake build mcpplibs-primitives
154-
xmake run basic # equivalent to ex01_default_arithmetic
156+
xmake run basic # compatibility alias for ex01_basic_usage
157+
xmake run ex01_basic_usage
158+
xmake run ex06_conversion
159+
xmake run ex07_algorithms
155160
xmake run ex05_concurrency_policy
156161
xmake run primitives_test
157162
```
@@ -161,7 +166,9 @@ xmake run primitives_test
161166
```bash
162167
cmake -B build -G Ninja
163168
cmake --build build --target mcpplibs-primitives
164-
cmake --build build --target ex01_default_arithmetic
169+
cmake --build build --target ex01_basic_usage
170+
cmake --build build --target ex06_conversion
171+
cmake --build build --target ex07_algorithms
165172
cmake --build build --target basic_tests
166173
ctest --test-dir build --output-on-failure
167174
```

README.zh.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ if (v.compare_exchange(expected, 3)) {
9898

9999
## 示例程序
100100

101-
- `ex01_default_arithmetic`: 默认策略下的基础算术运算示例
101+
- `ex01_basic_usage`: 演示 literal 与 primitive 工厂函数联合使用,并覆盖更多内置操作符
102102
- `ex02_type_policy`: 展示 `strict/compatible` 的类型协商差异,并包含 `underlying` 构造路径对 type 策略的影响。
103103
- `ex03_value_policy`: 展示 `checked/unchecked/saturating`,并包含与 `underlying` 的混合二元运算行为。
104104
- `ex04_error_policy`: 展示不同 error 策略的处理方式。
105105
- `ex05_concurrency_policy`: 读写组合并发场景(writer `store` + reader `add/sub` + `CAS`)示例。
106-
- `ex06_custom_underlying`: 自定义 underlying traits、rep 校验与 common rep 扩展。
107-
- `ex07_custom_policy`: 自定义策略协议实现示例。
108-
- `ex08_custom_operation`: 自定义 operation 扩展示例。
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 扩展示例。
109111

110112
## 项目结构
111113

@@ -117,7 +119,7 @@ mcpplibs-primitives/
117119
│ ├── policy/ # policy 标签与协议实现
118120
│ ├── operations/ # operation tags / dispatcher / operators
119121
│ └── underlying/ # underlying traits 与 common_rep
120-
├── examples/ # ex01 ~ ex08 示例
122+
├── examples/ # 示例程序
121123
├── tests/ # 测试入口与 basic 测试集
122124
├── xmake.lua # xmake 构建脚本
123125
├── CMakeLists.txt # CMake 构建脚本
@@ -151,7 +153,10 @@ xlings install
151153

152154
```bash
153155
xmake build mcpplibs-primitives
154-
xmake run basic # 等价于 ex01_default_arithmetic
156+
xmake run basic # 等价于 ex01_basic_usage
157+
xmake run ex01_basic_usage
158+
xmake run ex06_conversion
159+
xmake run ex07_algorithms
155160
xmake run ex05_concurrency_policy
156161
xmake run primitives_test
157162
```
@@ -161,7 +166,9 @@ xmake run primitives_test
161166
```bash
162167
cmake -B build -G Ninja
163168
cmake --build build --target mcpplibs-primitives
164-
cmake --build build --target ex01_default_arithmetic
169+
cmake --build build --target ex01_basic_usage
170+
cmake --build build --target ex06_conversion
171+
cmake --build build --target ex07_algorithms
165172
cmake --build build --target basic_tests
166173
ctest --test-dir build --output-on-failure
167174
```

docs/guide/en/extension.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Required members:
1818

1919
After registration, your type can be used as `primitive<YourType, ...>` if it satisfies `underlying_type`.
2020

21-
Reference example: `examples/ex06_custom_underlying.cpp`.
21+
Reference example: `examples/ex08_custom_underlying.cpp`.
2222

2323
## 2) Custom Common Rep Negotiation
2424

@@ -47,7 +47,7 @@ Custom policies require:
4747
4848
If your value policy needs operation runtime behavior, also provide `operations::runtime::op_binding` specializations.
4949
50-
Reference example: `examples/ex07_custom_policy.cpp`.
50+
Reference example: `examples/ex09_custom_policy.cpp`.
5151
5252
## 4) Custom Operation Tags
5353
@@ -61,7 +61,7 @@ To add new operation tags:
6161
3. Provide `operations::runtime::op_binding<OpTag, ValuePolicy, CommonRep>`.
6262
4. Invoke via `operations::apply<OpTag>(lhs, rhs)`.
6363
64-
Reference example: `examples/ex08_custom_operation.cpp`.
64+
Reference example: `examples/ex10_custom_operation.cpp`.
6565
6666
## Extension Checklist
6767

docs/guide/en/installation-and-build.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ xmake build mcpplibs-primitives
2121
Run an example:
2222

2323
```bash
24-
xmake run ex01_default_arithmetic
24+
xmake run ex01_basic_usage
2525
```
2626

2727
Run tests:
@@ -36,7 +36,7 @@ Compatibility alias:
3636
xmake run basic
3737
```
3838

39-
`basic` runs `ex01_default_arithmetic`.
39+
`basic` runs `ex01_basic_usage`.
4040

4141
## Build with CMake
4242

@@ -50,7 +50,9 @@ cmake --build build --target mcpplibs-primitives
5050
Build an example and tests:
5151

5252
```bash
53-
cmake --build build --target ex01_default_arithmetic
53+
cmake --build build --target ex01_basic_usage
54+
cmake --build build --target ex06_conversion
55+
cmake --build build --target ex07_algorithms
5456
cmake --build build --target basic_tests
5557
ctest --test-dir build --output-on-failure
5658
```
@@ -59,14 +61,16 @@ ctest --test-dir build --output-on-failure
5961

6062
Examples are available as independent targets:
6163

62-
- `ex01_default_arithmetic`
64+
- `ex01_basic_usage`
6365
- `ex02_type_policy`
6466
- `ex03_value_policy`
6567
- `ex04_error_policy`
6668
- `ex05_concurrency_policy`
67-
- `ex06_custom_underlying`
68-
- `ex07_custom_policy`
69-
- `ex08_custom_operation`
69+
- `ex06_conversion`
70+
- `ex07_algorithms`
71+
- `ex08_custom_underlying`
72+
- `ex09_custom_policy`
73+
- `ex10_custom_operation`
7074

7175
## Common Build Issues
7276

docs/guide/en/quick-start.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ This gives safe arithmetic and explicit error handling without requiring excepti
3838
3939
Run examples in this order:
4040
41-
1. `ex01_default_arithmetic`
41+
1. `ex01_basic_usage`
4242
2. `ex02_type_policy`
4343
3. `ex03_value_policy`
4444
4. `ex04_error_policy`
4545
5. `ex05_concurrency_policy`
46-
6. `ex06_custom_underlying`
47-
7. `ex07_custom_policy`
48-
8. `ex08_custom_operation`
46+
6. `ex06_conversion`
47+
7. `ex07_algorithms`
48+
8. `ex08_custom_underlying`
49+
9. `ex09_custom_policy`
50+
10. `ex10_custom_operation`
4951
5052
Command:
5153

docs/guide/zh/extension.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
完成后,只要满足 `underlying_type`,即可用于 `primitive<YourType, ...>`
2020

21-
参考:`examples/ex06_custom_underlying.cpp`
21+
参考:`examples/ex08_custom_underlying.cpp`
2222

2323
## 2) 自定义 common rep 协商
2424

@@ -47,7 +47,7 @@ struct mcpplibs::primitives::underlying::common_rep_traits<LhsRep, RhsRep> {
4747
4848
如果 value policy 需要参与运行期运算逻辑,还要补充 `operations::runtime::op_binding` 特化。
4949
50-
参考:`examples/ex07_custom_policy.cpp`
50+
参考:`examples/ex09_custom_policy.cpp`
5151
5252
## 4) 自定义 operation 标签
5353
@@ -61,7 +61,7 @@ struct mcpplibs::primitives::underlying::common_rep_traits<LhsRep, RhsRep> {
6161
3. 提供 `operations::runtime::op_binding<OpTag, ValuePolicy, CommonRep>`。
6262
4. 通过 `operations::apply<OpTag>(lhs, rhs)` 调用。
6363
64-
参考:`examples/ex08_custom_operation.cpp`
64+
参考:`examples/ex10_custom_operation.cpp`
6565
6666
## 扩展检查清单
6767

docs/guide/zh/installation-and-build.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ xmake build mcpplibs-primitives
2121
运行示例:
2222

2323
```bash
24-
xmake run ex01_default_arithmetic
24+
xmake run ex01_basic_usage
2525
```
2626

2727
运行测试:
@@ -36,7 +36,7 @@ xmake run primitives_test
3636
xmake run basic
3737
```
3838

39-
`basic` 对应 `ex01_default_arithmetic`
39+
`basic` 对应 `ex01_basic_usage`
4040

4141
## 使用 CMake 构建
4242

@@ -50,7 +50,9 @@ cmake --build build --target mcpplibs-primitives
5050
构建示例与测试:
5151

5252
```bash
53-
cmake --build build --target ex01_default_arithmetic
53+
cmake --build build --target ex01_basic_usage
54+
cmake --build build --target ex06_conversion
55+
cmake --build build --target ex07_algorithms
5456
cmake --build build --target basic_tests
5557
ctest --test-dir build --output-on-failure
5658
```
@@ -59,14 +61,16 @@ ctest --test-dir build --output-on-failure
5961

6062
可独立构建/运行的示例目标:
6163

62-
- `ex01_default_arithmetic`
64+
- `ex01_basic_usage`
6365
- `ex02_type_policy`
6466
- `ex03_value_policy`
6567
- `ex04_error_policy`
6668
- `ex05_concurrency_policy`
67-
- `ex06_custom_underlying`
68-
- `ex07_custom_policy`
69-
- `ex08_custom_operation`
69+
- `ex06_conversion`
70+
- `ex07_algorithms`
71+
- `ex08_custom_underlying`
72+
- `ex09_custom_policy`
73+
- `ex10_custom_operation`
7074

7175
## 常见构建问题
7276

docs/guide/zh/quick-start.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ int main() {
3838
3939
建议按以下顺序运行示例:
4040
41-
1. `ex01_default_arithmetic`
41+
1. `ex01_basic_usage`
4242
2. `ex02_type_policy`
4343
3. `ex03_value_policy`
4444
4. `ex04_error_policy`
4545
5. `ex05_concurrency_policy`
46-
6. `ex06_custom_underlying`
47-
7. `ex07_custom_policy`
48-
8. `ex08_custom_operation`
46+
6. `ex06_conversion`
47+
7. `ex07_algorithms`
48+
8. `ex08_custom_underlying`
49+
9. `ex09_custom_policy`
50+
10. `ex10_custom_operation`
4951
5052
运行示例:
5153

0 commit comments

Comments
 (0)