Skip to content

Commit f580e6b

Browse files
refactor: Rename example files for clarity and update references in CMake and Lua scripts
Signed-off-by: FrozenlemonTee <1115306170@qq.com>
1 parent 3dd192a commit f580e6b

6 files changed

Lines changed: 30 additions & 74 deletions

File tree

examples/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
set(PRIMITIVES_EXAMPLE_SOURCES
2-
ex01_default_arithmetic.cpp
2+
ex01_basic_usage.cpp
33
ex02_type_policy.cpp
44
ex03_value_policy.cpp
55
ex04_error_policy.cpp
66
ex05_concurrency_policy.cpp
7-
ex06_custom_underlying.cpp
8-
ex07_custom_policy.cpp
9-
ex08_custom_operation.cpp
7+
ex06_conversion.cpp
8+
ex07_algorithms.cpp
9+
ex08_custom_underlying.cpp
10+
ex09_custom_policy.cpp
11+
ex10_custom_operation.cpp
1012
)
1113

1214
foreach(example_source IN LISTS PRIMITIVES_EXAMPLE_SOURCES)

examples/ex01_default_arithmetic.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Example: ex06_custom_underlying
2+
* Example: ex08_custom_underlying
33
*
44
* Purpose:
55
* Demonstrate custom underlying integration, including rep bridge,
@@ -20,7 +20,7 @@ import mcpplibs.primitives;
2020

2121
using namespace mcpplibs::primitives;
2222

23-
// Point 6 / Step 1: Define custom domain value types.
23+
// Point 8 / Step 1: Define custom domain value types.
2424
struct UserInteger {
2525
int value;
2626
};
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Example: ex07_custom_policy
2+
* Example: ex09_custom_policy
33
*
44
* Purpose:
55
* Show end-to-end customization of all policy dimensions (type, value,
@@ -24,14 +24,14 @@ import mcpplibs.primitives.operations.invoker;
2424
using namespace mcpplibs::primitives;
2525

2626
namespace demo {
27-
// Point 7 / Step 1: Define one custom tag for each policy dimension.
27+
// Point 9 / Step 1: Define one custom tag for each policy dimension.
2828
struct custom_value {};
2929
struct custom_type {};
3030
struct custom_error {};
3131
struct custom_concurrency {};
3232
} // namespace demo
3333

34-
// Point 7 / Step 2: Register tags into policy::traits.
34+
// Point 9 / Step 2: Register tags into policy::traits.
3535
template <> struct mcpplibs::primitives::policy::traits<demo::custom_value> {
3636
using policy_type = demo::custom_value;
3737
static constexpr bool enabled = true;
@@ -57,7 +57,7 @@ struct mcpplibs::primitives::policy::traits<demo::custom_concurrency> {
5757
static constexpr auto kind = category::concurrency;
5858
};
5959

60-
// Point 7 / Step 3A: Implement custom type handler.
60+
// Point 9 / Step 3A: Implement custom type handler.
6161
// Always allow and negotiate through std::common_type_t.
6262
template <operations::operation OpTag, typename LhsRep, typename RhsRep>
6363
struct mcpplibs::primitives::policy::type::handler<demo::custom_type, OpTag,
@@ -68,7 +68,7 @@ struct mcpplibs::primitives::policy::type::handler<demo::custom_type, OpTag,
6868
using common_rep = std::common_type_t<LhsRep, RhsRep>;
6969
};
7070

71-
// Point 7 / Step 3B: Implement custom concurrency handler.
71+
// Point 9 / Step 3B: Implement custom concurrency handler.
7272
template <operations::operation OpTag, typename CommonRep,
7373
typename ErrorPayload>
7474
struct mcpplibs::primitives::policy::concurrency::handler<
@@ -115,7 +115,7 @@ struct mcpplibs::primitives::policy::concurrency::handler<
115115
}
116116
};
117117

118-
// Point 7 / Step 3C: Implement custom value handler.
118+
// Point 9 / Step 3C: Implement custom value handler.
119119
// Complex point: finalize() post-processes decision and adjusts output.
120120
template <operations::operation OpTag, typename CommonRep,
121121
typename ErrorPayload>
@@ -138,7 +138,7 @@ struct mcpplibs::primitives::policy::value::handler<demo::custom_value, OpTag,
138138
}
139139
};
140140

141-
// Point 7 / Step 3D: Provide binding for custom value policy + Addition.
141+
// Point 9 / Step 3D: Provide binding for custom value policy + Addition.
142142
// Without this specialization, runtime::run_value static_assert will fail.
143143
template <typename CommonRep>
144144
struct mcpplibs::primitives::operations::runtime::op_binding<
@@ -154,7 +154,7 @@ struct mcpplibs::primitives::operations::runtime::op_binding<
154154
}
155155
};
156156

157-
// Point 7 / Step 3E: Implement custom error handler.
157+
// Point 9 / Step 3E: Implement custom error handler.
158158
template <operations::operation OpTag, typename CommonRep,
159159
typename ErrorPayload>
160160
struct mcpplibs::primitives::policy::error::handler<demo::custom_error, OpTag,
@@ -169,7 +169,7 @@ struct mcpplibs::primitives::policy::error::handler<demo::custom_error, OpTag,
169169
};
170170

171171
int main() {
172-
// Point 7 / Step 4: Compose all custom tags and execute a call path.
172+
// Point 9 / Step 4: Compose all custom tags and execute a call path.
173173
using custom_t = primitive<int, demo::custom_value, demo::custom_type,
174174
demo::custom_error, demo::custom_concurrency>;
175175

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Example: ex08_custom_operation
2+
* Example: ex10_custom_operation
33
*
44
* Purpose:
55
* Demonstrate how to register new operation tags, declare operation traits,
@@ -19,13 +19,13 @@ import mcpplibs.primitives.operations.invoker;
1919
using namespace mcpplibs::primitives;
2020

2121
namespace demo_ops {
22-
// Point 8 / Step 1: Define custom operation tags.
22+
// Point 10 / Step 1: Define custom operation tags.
2323
struct Average {};
2424
struct GreaterThan {};
2525
struct BitAnd {};
2626
} // namespace demo_ops
2727

28-
// Point 8 / Step 2: Register operation traits for
28+
// Point 10 / Step 2: Register operation traits for
2929
// arithmetic/comparison/bitwise.
3030
template <> struct mcpplibs::primitives::operations::traits<demo_ops::Average> {
3131
using op_tag = demo_ops::Average;
@@ -49,7 +49,7 @@ template <> struct mcpplibs::primitives::operations::traits<demo_ops::BitAnd> {
4949
static constexpr auto capability_mask = capability::bitwise;
5050
};
5151

52-
// Point 8 / Step 3: Provide runtime op_binding for each new operation.
52+
// Point 10 / Step 3: Provide runtime op_binding for each new operation.
5353
// Complex point: these specializations plug directly into run_value dispatch.
5454
template <typename CommonRep>
5555
struct mcpplibs::primitives::operations::runtime::op_binding<
@@ -94,7 +94,7 @@ struct mcpplibs::primitives::operations::runtime::op_binding<
9494
};
9595

9696
int main() {
97-
// Point 8 / Step 4: Invoke each custom operation through operations::apply.
97+
// Point 10 / Step 4: Invoke each custom operation through operations::apply.
9898
using value_t =
9999
primitive<int, policy::value::checked, policy::error::expected>;
100100

examples/xmake.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ add_rules("mode.debug", "mode.release")
33
set_languages("c++23")
44

55
local examples = {
6-
"ex01_default_arithmetic",
6+
"ex01_basic_usage",
77
"ex02_type_policy",
88
"ex03_value_policy",
99
"ex04_error_policy",
1010
"ex05_concurrency_policy",
11-
"ex06_custom_underlying",
12-
"ex07_custom_policy",
13-
"ex08_custom_operation"
11+
"ex06_conversion",
12+
"ex07_algorithms",
13+
"ex08_custom_underlying",
14+
"ex09_custom_policy",
15+
"ex10_custom_operation"
1416
}
1517

16-
-- CI compatibility alias: keep `xmake run basic` working.
18+
-- CI compatibility alias: keep `xmake run basic` working for ex01_basic_usage.
1719
target("basic")
1820
set_kind("binary")
19-
add_files("ex01_default_arithmetic.cpp")
21+
add_files("ex01_basic_usage.cpp")
2022
add_deps("mcpplibs-primitives")
2123
set_policy("build.c++.modules", true)
2224

0 commit comments

Comments
 (0)