@chengzhao-dev/dsh-cpp-workflow 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +7 -7
- package/README.md +7 -7
- package/lib/client.js +1 -1
- package/lib/comment-policy.js +1 -1
- package/lib/index.js +3 -3
- package/package.json +9 -3
- package/skills/building-cpp/SKILL.md +15 -15
- package/skills/building-cpp/examples/environment.md +4 -3
- package/skills/building-cpp/references/{build-script.md → 01-build-script.md} +4 -3
- package/skills/building-cpp/references/{environment.md → 02-environment.md} +3 -2
- package/skills/building-cpp/steps/01-build.md +2 -2
- package/skills/building-cpp/steps/02-tooling.md +12 -12
- package/skills/building-cpp/steps/03-check.md +5 -5
- package/skills/building-cpp/{project/vscode/02-settings.md → steps/04-vscode.md} +24 -6
- package/skills/developing-cpp/SKILL.md +13 -13
- package/skills/developing-cpp/references/comments/{comment-rules.md → 01-comment-rules.md} +52 -47
- package/skills/developing-cpp/references/comments/{comment-style.md → 02-style.md} +11 -7
- package/skills/developing-cpp/references/comments/examples/{declaration-class.md → 01-declaration-class.md} +2 -1
- package/skills/developing-cpp/references/comments/examples/{declaration-constructor.md → 02-declaration-constructor.md} +2 -1
- package/skills/developing-cpp/references/comments/examples/{declaration-enum.md → 03-declaration-enum.md} +3 -3
- package/skills/developing-cpp/references/comments/examples/{declaration-file.md → 04-declaration-file.md} +4 -3
- package/skills/developing-cpp/references/comments/examples/{declaration-function.md → 05-declaration-function.md} +10 -29
- package/skills/developing-cpp/references/comments/examples/{declaration-member.md → 06-declaration-member.md} +1 -0
- package/skills/developing-cpp/references/comments/examples/07-declaration-predicate.md +15 -0
- package/skills/developing-cpp/references/comments/examples/{declaration-struct.md → 08-declaration-struct.md} +1 -0
- package/skills/developing-cpp/references/comments/examples/09-implementation-body.md +114 -0
- package/skills/developing-cpp/references/comments/examples/10-implementation-todo.md +17 -0
- package/skills/developing-cpp/references/comments/glossary/{comment-terms.md → 01-comment-terms.md} +8 -7
- package/skills/developing-cpp/references/design/{project-design.md → 01-project-design.md} +8 -7
- package/skills/developing-cpp/references/design/examples/{behavior-sentence.md → 01-behavior-sentence.md} +1 -0
- package/skills/developing-cpp/references/design/examples/{coordinate-table.md → 02-coordinate-table.md} +1 -0
- package/skills/developing-cpp/references/design/examples/{header-place.md → 03-header-place.md} +1 -0
- package/skills/developing-cpp/references/design/examples/{library-boundary.md → 04-library-boundary.md} +3 -2
- package/skills/developing-cpp/references/design/examples/{library-split.md → 05-library-split.md} +1 -0
- package/skills/developing-cpp/references/design/examples/{move-result.md → 06-move-result.md} +4 -10
- package/skills/developing-cpp/references/design/examples/{preview-read.md → 07-preview-read.md} +1 -0
- package/skills/developing-cpp/references/design/examples/08-screen-enter-exit.md +40 -0
- package/skills/developing-cpp/references/design/session-layer.md +91 -0
- package/skills/developing-cpp/references/exceptions/{throw-rules.md → 01-exception-rules.md} +10 -18
- package/skills/developing-cpp/references/exceptions/examples/{throw-boundary.md → 01-throw-boundary.md} +1 -0
- package/skills/developing-cpp/references/exceptions/examples/{throw-build-mode.md → 02-throw-build-mode.md} +3 -2
- package/skills/developing-cpp/references/exceptions/examples/{throw-catch.md → 03-throw-catch.md} +1 -0
- package/skills/developing-cpp/references/exceptions/examples/{throw-destructor.md → 04-throw-destructor.md} +1 -0
- package/skills/developing-cpp/references/exceptions/examples/{throw-format.md → 05-throw-format.md} +1 -0
- package/skills/developing-cpp/references/exceptions/examples/{throw-message.md → 06-throw-message.md} +2 -1
- package/skills/developing-cpp/references/exceptions/examples/{throw-when.md → 07-throw-when.md} +1 -0
- package/skills/developing-cpp/references/index.md +134 -0
- package/skills/developing-cpp/references/language/glossary/{language-terms.md → 01-language-terms.md} +3 -2
- package/skills/developing-cpp/references/language/language-basics/01-objects.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/02-initialization.md +15 -7
- package/skills/developing-cpp/references/language/language-basics/03-deduction.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/04-const.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/05-expressions.md +7 -3
- package/skills/developing-cpp/references/language/language-basics/06-functions.md +6 -3
- package/skills/developing-cpp/references/language/language-basics/07-classes.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/08-raii.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/09-templates.md +1 -0
- package/skills/developing-cpp/references/language/language-basics/{10-checklist.md → 10-language-checklist.md} +2 -0
- package/skills/developing-cpp/references/language/performance/01-measure.md +1 -0
- package/skills/developing-cpp/references/language/performance/02-complexity.md +1 -0
- package/skills/developing-cpp/references/language/performance/03-memory.md +1 -0
- package/skills/developing-cpp/references/language/performance/04-undefined-behavior.md +1 -0
- package/skills/developing-cpp/references/language/performance/05-pitfalls.md +1 -0
- package/skills/developing-cpp/references/language/performance/06-false-optimizations.md +1 -0
- package/skills/developing-cpp/references/language/performance/07-checklist.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/01-containers.md +5 -3
- package/skills/developing-cpp/references/language/standard-library/02-access.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/03-iteration.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/05-string.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/06-format.md +5 -2
- package/skills/developing-cpp/references/language/standard-library/07-time.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/08-random.md +2 -0
- package/skills/developing-cpp/references/language/standard-library/09-files.md +1 -0
- package/skills/developing-cpp/references/language/standard-library/{10-checklist.md → 10-library-checklist.md} +2 -1
- package/skills/developing-cpp/references/language/value-types/01-width.md +1 -0
- package/skills/developing-cpp/references/language/value-types/02-signed.md +1 -0
- package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +1 -0
- package/skills/developing-cpp/references/language/value-types/04-enum.md +13 -1
- package/skills/developing-cpp/references/language/value-types/05-strong-type.md +1 -0
- package/skills/developing-cpp/references/language/value-types/06-const-method.md +1 -0
- package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +1 -0
- package/skills/developing-cpp/references/language/value-types/08-comparison.md +1 -0
- package/skills/developing-cpp/references/language/value-types/09-subscript.md +2 -1
- package/skills/developing-cpp/references/language/value-types/10-float-bool.md +1 -0
- package/skills/developing-cpp/references/language/value-types/11-checklist.md +2 -0
- package/skills/developing-cpp/references/layout/01-source-layout.md +3 -2
- package/skills/developing-cpp/references/layout/02-file-template.md +4 -3
- package/skills/developing-cpp/references/layout/03-declaration-order.md +15 -4
- package/skills/developing-cpp/references/naming/{identifier-names.md → 01-identifier-names.md} +31 -9
- package/skills/developing-cpp/references/naming/examples/{naming-accessor.md → 01-naming-accessor.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/02-naming-basic.md +4 -0
- package/skills/developing-cpp/references/naming/examples/{naming-current-prefix.md → 03-naming-current-prefix.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-local.md → 04-naming-local.md} +2 -1
- package/skills/developing-cpp/references/naming/examples/{naming-lookup.md → 05-naming-lookup.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-lower-layer.md → 06-naming-lower-layer.md} +2 -2
- package/skills/developing-cpp/references/naming/examples/{naming-multiple-return.md → 07-naming-multiple-return.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-player-value.md → 08-naming-player-value.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-predicate.md → 09-naming-predicate.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-rename.md → 10-naming-rename.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-responsibility.md → 11-naming-responsibility.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-role.md → 12-naming-role.md} +1 -0
- package/skills/developing-cpp/references/naming/examples/{naming-state-change.md → 13-naming-state-change.md} +4 -4
- package/skills/developing-cpp/references/naming/glossary/01-naming-terms.md +28 -0
- package/skills/developing-cpp/references/naming/glossary/{position.md → 02-position.md} +2 -1
- package/skills/developing-cpp/references/naming/glossary/03-selection.md +23 -0
- package/skills/developing-cpp/references/naming/glossary/{square.md → 04-square.md} +3 -2
- package/skills/developing-cpp/references/naming/glossary/05-scoring.md +27 -0
- package/skills/developing-cpp/references/naming/glossary/06-difficulty.md +26 -0
- package/skills/developing-cpp/references/naming/glossary/07-stream.md +21 -0
- package/skills/developing-cpp/references/style/{google-cpp-style.md → 01-google-cpp-style.md} +16 -9
- package/skills/developing-cpp/scripts/checking-comments.mjs +107 -8
- package/skills/developing-cpp/steps/01-behavior.md +5 -5
- package/skills/developing-cpp/steps/02-boundary.md +6 -6
- package/skills/developing-cpp/steps/03-declaration.md +8 -8
- package/skills/developing-cpp/steps/04-implementation.md +17 -17
- package/skills/engineering/SKILL.md +14 -14
- package/skills/engineering/references/cmake/linking/01-libraries.md +7 -4
- package/skills/engineering/references/cmake/linking/02-rpath.md +1 -0
- package/skills/engineering/references/cmake/linking/03-undefined-reference.md +2 -1
- package/skills/engineering/references/cmake/linking/04-inspect.md +1 -1
- package/skills/engineering/references/cmake/modules/{functions.md → 01-functions.md} +3 -2
- package/skills/engineering/references/cmake/standards/{cxx-standard.md → 01-cxx-standard.md} +3 -2
- package/skills/engineering/references/cmake/standards/examples/{standard.md → 01-standard.md} +2 -1
- package/skills/engineering/references/cmake/standards/{README.md → index.md} +16 -15
- package/skills/engineering/references/cmake/standards/versions.md +44 -0
- package/skills/engineering/references/cmake/targets/{rules.md → 01-target-rules.md} +37 -5
- package/skills/engineering/references/cmake/targets/examples/{rpath.md → 01-rpath.md} +1 -0
- package/skills/engineering/references/cmake/testing/{ctest.md → 01-ctest.md} +3 -2
- package/skills/engineering/references/formatting/01-encoding.md +2 -1
- package/skills/engineering/references/formatting/02-clang-format.md +4 -2
- package/skills/engineering/references/formatting/03-clang-tidy.md +3 -2
- package/skills/engineering/references/formatting/04-clangd.md +2 -0
- package/skills/engineering/references/formatting/examples/{clang-format.md → 01-clang-format.md} +2 -1
- package/skills/engineering/references/formatting/examples/{clang-tidy.md → 02-clang-tidy.md} +1 -0
- package/skills/engineering/references/formatting/examples/{clangd.md → 03-clangd.md} +1 -0
- package/skills/engineering/references/index.md +32 -0
- package/skills/engineering/steps/01-targets.md +3 -3
- package/skills/engineering/steps/02-modules.md +3 -3
- package/skills/engineering/steps/03-check.md +1 -1
- package/skills/shared/budget.md +20 -0
- package/skills/{developing-cpp/references/editing/01-edit-operations.md → shared/operations.md} +7 -3
- package/skills/{developing-cpp/references/editing/02-rule-priority.md → shared/rule-priority.md} +8 -1
- package/skills/building-cpp/project/vscode/01-extensions.md +0 -28
- package/skills/developing-cpp/references/comments/examples/declaration-predicate.md +0 -14
- package/skills/developing-cpp/references/comments/examples/implementation-body.md +0 -81
- package/skills/developing-cpp/references/comments/examples/implementation-todo.md +0 -16
- package/skills/developing-cpp/references/naming/examples/naming-basic.md +0 -3
- package/skills/developing-cpp/references/naming/glossary/naming-terms.md +0 -23
- package/skills/engineering/references/cmake/standards/c++11/README.md +0 -50
- package/skills/engineering/references/cmake/standards/c++14/README.md +0 -48
- package/skills/engineering/references/cmake/standards/c++17/README.md +0 -50
- package/skills/engineering/references/cmake/standards/c++20/README.md +0 -50
- package/skills/engineering/references/cmake/standards/c++23/README.md +0 -50
- package/skills/engineering/references/cmake/targets/examples/glob.md +0 -22
- package/skills/engineering/references/cmake/targets/examples/target.md +0 -156
- /package/skills/engineering/{references/formatting/scripts → scripts}/checking-encoding.mjs +0 -0
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
<!-- 读取时机:配 CMake 或工具链时;读完能回答:语言标准档案;预算:一次只开这一份(165 行),不自动串联。 -->
|
|
1
2
|
# 语言标准档案
|
|
2
3
|
|
|
3
4
|
本工作流默认 **C++23**,但一个工程只选一个 `standard`,不为同一份源码承诺“同时兼容 C++11–C++23”。标准是项目级事实,写在项目的 `environment.json`(本书在 `.agents/skills/cpp-workflow-project/environment.json`)。
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
各档的编译器下限、能用/不能假设、降档要改什么集中在 [versions.md](versions.md);`c++11/`–`c++23/` 只保留这一档的 `cmake-snippet.cmake`。模板仍然只有一套公共骨架,靠 `__cplusplus` 条件选择实现,不复制五份模板。
|
|
6
7
|
|
|
7
|
-
Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [
|
|
8
|
+
Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [01-exception-rules.md](../../../../developing-cpp/references/exceptions/01-exception-rules.md)。
|
|
8
9
|
|
|
9
10
|
## 选择标准
|
|
10
11
|
|
|
11
|
-
| 标准 |
|
|
12
|
+
| 标准 | 差异 | 一句话 |
|
|
12
13
|
| --- | --- | --- |
|
|
13
|
-
| C++11 | [
|
|
14
|
-
| C++14 | [
|
|
15
|
-
| C++17 | [
|
|
16
|
-
| C++20 | [
|
|
17
|
-
| C++23 | [
|
|
14
|
+
| C++11 | [versions.md#c11](versions.md#c11) | 老工具链、老库仍要维护时的最低档 |
|
|
15
|
+
| C++14 | [versions.md#c14](versions.md#c14) | 需要 `make_unique`、泛型 lambda,但还不想上 C++17 |
|
|
16
|
+
| C++17 | [versions.md#c17](versions.md#c17) | 需要 `string_view`、`optional`、`if constexpr` 的稳定基线 |
|
|
17
|
+
| C++20 | [versions.md#c20](versions.md#c20) | 需要 concepts、ranges、`std::format` 的现代基线 |
|
|
18
|
+
| C++23 | [versions.md#c23](versions.md#c23) | 本工作流默认;需要 `print`、`expected` 等设施时选它 |
|
|
18
19
|
|
|
19
|
-
新工程写 `c++23`;已有工程按现有 `CMakeLists.txt`
|
|
20
|
+
新工程写 `c++23`;已有工程按现有 `CMakeLists.txt` 和编译器能力选,不为了“统一”擅自升降。降档前先读 `versions.md` 对应一节的“不能假设”和“降档要改什么”。
|
|
20
21
|
|
|
21
22
|
## 三个规划粒度
|
|
22
23
|
|
|
@@ -24,7 +25,7 @@ Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++2
|
|
|
24
25
|
| --- | --- | --- |
|
|
25
26
|
| 项目 | 本页选择表、编译器/库门槛 | `environment.json` 的 `standard`,以及“为什么选这档” |
|
|
26
27
|
| target | 该档的 `cmake-snippet.cmake` | `cxx_std_*`、`CXX_STANDARD`、`CXX_STANDARD_REQUIRED`、`CXX_EXTENSIONS` |
|
|
27
|
-
| 代码/工具 |
|
|
28
|
+
| 代码/工具 | `versions.md` 的“能用/不能假设/降档” | 设施替换、`.clang-format` 档位、`.clangd` 不写 `-std` |
|
|
28
29
|
| 验证 | 本页验证矩阵、`scripts/checking-standard-matrix.sh` | configure/build/CTest 和 `compile_commands.json` 的精确 `-std` |
|
|
29
30
|
|
|
30
31
|
每个标准目录都按这四层写;不要只在项目层改 `standard`,却在 target 层留着 C++23 的 `cxx_std_23`。
|
|
@@ -69,7 +70,7 @@ set_target_properties(app PROPERTIES
|
|
|
69
70
|
```
|
|
70
71
|
|
|
71
72
|
- `cxx_std_23` 是“至少”,会向依赖它的 target 传播。
|
|
72
|
-
- `CXX_STANDARD` 是请求值;`CXX_STANDARD_REQUIRED ON`
|
|
73
|
+
- `CXX_STANDARD` 是请求值;`CXX_STANDARD_REQUIRED ON` 防止编译器不支持时静默降级。
|
|
73
74
|
- `CXX_EXTENSIONS OFF` 把 `-std=gnu++23` 收成 `-std=c++23`。
|
|
74
75
|
- configure 后读 `compile_commands.json` 中每个 target 的 `-std=`;每个 target 只能有一条,必须是 `-std=c++NN`,不能是 `gnu++NN`,不同值即失败。
|
|
75
76
|
- CMake 最低 3.20(模板统一要求);只单独使用低档片段时,C++11/14 的 `cxx_std_*` meta-feature 最低 3.1,C++17 为 3.8,C++20 为 3.12。C++23 的 `CXX_STANDARD 23` 自 3.20 才有。
|
|
@@ -151,7 +152,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
|
|
|
151
152
|
|
|
152
153
|
增加 C++26 或更高标准时,不复制模板,按这个顺序做:
|
|
153
154
|
|
|
154
|
-
1.
|
|
155
|
+
1. 在 `versions.md` 增加 C++26 一节,新建 `standards/c++26/cmake-snippet.cmake` 并改数字。
|
|
155
156
|
2. 更新本页矩阵和 `checking-environment.mjs` 的 `STANDARDS`。
|
|
156
157
|
3. 确认 CMake 的 `CXX_STANDARD 26`、clang-format 的 `Standard` 能力、编译器/标准库门槛。
|
|
157
158
|
4. 在四套模板 × 新档上跑 configure/build/CTest,并在 `compile_commands.json` 核对 `-std=c++26`。
|
|
@@ -159,7 +160,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
|
|
|
159
160
|
|
|
160
161
|
## 相关文件
|
|
161
162
|
|
|
162
|
-
- [environment.md](../../../../building-cpp/references/environment.md):四轴声明与校验。
|
|
163
|
-
- [cxx-standard.md](cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
|
|
164
|
-
- [clang-tidy.md](../../formatting/03-clang-tidy.md):clang-format / clang-tidy / clangd 分工。
|
|
163
|
+
- [02-environment.md](../../../../building-cpp/references/02-environment.md):四轴声明与校验。
|
|
164
|
+
- [01-cxx-standard.md](01-cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
|
|
165
|
+
- [03-clang-tidy.md](../../formatting/03-clang-tidy.md):clang-format / clang-tidy / clangd 分工。
|
|
165
166
|
- [01-build.md](../../../../building-cpp/steps/01-build.md):定构建步骤。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!-- 读取时机:配 CMake 或工具链时;读完能回答:C++11–C++23 各档差异;预算:一次只开这一份(43 行),不自动串联。 -->
|
|
2
|
+
# 各标准差异
|
|
3
|
+
|
|
4
|
+
本页只列每档相对前一档多出什么、不能假设什么、降到这一档要改什么。选择表、共用矩阵、CMake/clang-format/clangd 共用规则与验证矩阵在 [index.md](index.md);每档的 CMake 片段在 `c++NN/cmake-snippet.cmake`。
|
|
5
|
+
|
|
6
|
+
## C++11
|
|
7
|
+
|
|
8
|
+
- 能用:`auto`、范围 `for`、lambda、右值引用与移动语义、`std::unique_ptr`/`shared_ptr`、`std::thread`/`chrono`、`enum class`、`override`/`final`、变参模板、受限 `constexpr`、`std::array`、`unordered_map`/`unordered_set`。
|
|
9
|
+
- 不能假设:`std::make_unique`、泛型 lambda、变量模板、返回类型推导、`std::string_view`、`std::optional`、`std::variant`、`if constexpr`、结构化绑定、`[[nodiscard]]`、`std::filesystem`、`std::format`、`std::print`;不要用 C++14 的放宽 `constexpr` 写循环或多语句函数。
|
|
10
|
+
- 降档/升级:这是最低档;从 C++14 降到这里,先去掉 `std::make_unique`、泛型 lambda、返回类型推导和变量模板。`std::unique_ptr<T>(new T(...))` 只作过渡,不要在新代码里扩散。
|
|
11
|
+
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++11`,不能是 `gnu++11`;模板的 `__cplusplus` 分支走字符串拼接。
|
|
12
|
+
- 片段:[cmake-snippet.cmake](c++11/cmake-snippet.cmake)。
|
|
13
|
+
|
|
14
|
+
## C++14
|
|
15
|
+
|
|
16
|
+
- 能用:C++11 的全部内容;`std::make_unique`、泛型 lambda、变量模板、返回类型推导、二进制字面量、数字分隔符、放宽的 `constexpr`、`std::integer_sequence`。
|
|
17
|
+
- 不能假设:`std::string_view`、`std::optional`、`std::variant`、`if constexpr`、结构化绑定、`[[nodiscard]]`、`std::filesystem`、`std::format`、`std::print`;不要把 C++17 的写法靠编译器扩展通过。
|
|
18
|
+
- 降档/升级:从 C++17 降到这里,把 `string_view` 改成 `const std::string&`,把 `optional` 改成 `bool` + 输出参数或项目结果类型,把 `if constexpr` 改成标签分派或重载。升级到 C++17 后也不要立刻把公共接口全改成 `string_view`,先看调用方生命周期。
|
|
19
|
+
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++14`;模板在 C++14 下走字符串拼接。
|
|
20
|
+
- 片段:[cmake-snippet.cmake](c++14/cmake-snippet.cmake)。
|
|
21
|
+
|
|
22
|
+
## C++17
|
|
23
|
+
|
|
24
|
+
- 能用:C++14 的全部内容;`std::string_view`、`std::optional`、`std::variant`、`std::any`、`if constexpr`、结构化绑定、`[[nodiscard]]`、内联变量、嵌套命名空间、`std::filesystem`、并行算法(库实现和链接方式另看)。
|
|
25
|
+
- 不能假设:concepts、ranges、`std::format`、`std::span`、`std::bit_cast`、`std::print`、`std::expected`、`std::stacktrace`、`= default` 的比较运算符;`std::filesystem` 在 GCC 8 需要额外链接 `stdc++fs`,GCC 9 起才稳定。
|
|
26
|
+
- 降档/升级:从 C++20 降到这里,把 concepts 改成 `enable_if`/重载,把 ranges 改成迭代器算法,把 `std::format` 改成 `std::ostringstream`,把 `= default` 的比较运算符改回结构体外的手写自由函数。升级到 C++20 后先确认 `std::format` 的库门槛(libstdc++ 13+ / libc++ 14+),不要只看编译器版本。
|
|
27
|
+
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++17`;模板在 C++17 下仍走字符串拼接。
|
|
28
|
+
- 片段:[cmake-snippet.cmake](c++17/cmake-snippet.cmake)。
|
|
29
|
+
|
|
30
|
+
## C++20
|
|
31
|
+
|
|
32
|
+
- 能用:C++17 的全部内容;concepts、requires、ranges、`std::span`、`std::bit_cast`、`std::source_location`、`std::format`、协程、`std::jthread`、三路比较;调用方需要按成员逐项比较时写 `bool operator==(const T&) const = default`,C++23 沿用;模块语法可用,但工具链支持不完整,模板不使用。
|
|
33
|
+
- 不能假设:`std::print`、`std::expected`、`std::stacktrace`、`if consteval`、显式对象参数;`std::format` 不只看语言核心:libstdc++ 13+,libc++ 14+ 实现完成,但特性宏到 19 才稳定;模块、协程的构建支持因编译器/构建系统而异。
|
|
34
|
+
- 降档/升级:从 C++23 降到这里,把 `std::print` 改成 `std::format` + `std::cout`,把 `std::expected` 改成 `std::optional` 或项目结果类型,去掉 `if consteval`。升级到 C++23 后仍要逐项确认库实现,不要因为 `-std=c++23` 通过就假定 `print`/`stacktrace` 可用。
|
|
35
|
+
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++20`;模板在 C++20 下走 `std::format` 分支。
|
|
36
|
+
- 片段:[cmake-snippet.cmake](c++20/cmake-snippet.cmake)。
|
|
37
|
+
|
|
38
|
+
## C++23
|
|
39
|
+
|
|
40
|
+
- 能用:C++20 的全部内容;`std::print`/`std::println`、`std::expected`、`std::stacktrace`、`if consteval`、显式对象参数(deducing this)、`std::mdspan`、`std::flat_map`、ranges 的 C++23 增补(工具链实现为准)。
|
|
41
|
+
- 不能假设:C++23 在 GCC/Clang 上仍是 Partial,具体设施要查编译器状态页;`std::print` 的库门槛是 libstdc++ 14+ / libc++ 19+;`std::stacktrace` 还要链接对应库;`std::expected` 的 monadic 接口、`std::flat_map` 等设施在旧标准库上可能缺失;模板只用 `std::format`,不因为默认 C++23 就强依赖 `print`/`stacktrace`。
|
|
42
|
+
- 降档/升级:从 C++23 降到 C++20 见上一节;升级到 C++26 前先确认 CMake 3.25+、编译器/标准库支持、clang-format 的 `c++26` 枚举,并按 [index.md](index.md#新增标准) 的流程新增片段与矩阵行。
|
|
43
|
+
- 验证:`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++23`;模板在 C++23 下走 `std::format` 分支;若使用 `print`/`stacktrace`,另做链接测试。
|
|
44
|
+
- 片段:[cmake-snippet.cmake](c++23/cmake-snippet.cmake)。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 读取时机:配 CMake 或工具链时;读完能回答:CMake;预算:一次只开这一份(230 行),不自动串联。 -->
|
|
1
2
|
# CMake
|
|
2
3
|
|
|
3
4
|
目标:一个编译器、Ninja、target-based 规则、可用的编译数据库。下面是最小形状和常见边界;工程模板仍由 `building-cpp` 提供,在 `../../../../building-cpp/assets/templates/projects/`,可复用的 CMake 函数在本技能的 `assets/`:`CompileSettings.cmake` 收标准与警告,`LinkSettings.cmake` 收构建期 RPATH 与 GoogleTest 依赖。
|
|
@@ -61,19 +62,19 @@ CompileSettings_SetWarnings(greeting PRIVATE LEVEL standard)
|
|
|
61
62
|
|
|
62
63
|
- 库的 `PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include` 让程序与链接它的测试写 `#include "greeting.h"` 就能找到公共头,不需要各自再写 include 路径。
|
|
63
64
|
- 标准用 `CompileSettings_SetCxxStandard`:库用 `PUBLIC` 传播“至少 C++NN”,程序用 `PRIVATE`;`CXX_STANDARD`/`CXX_EXTENSIONS` 不传播,每个会编译的 target 都要自己调用一次。
|
|
64
|
-
- `CXX_STANDARD_REQUIRED ON` 防止 CMake
|
|
65
|
+
- `CXX_STANDARD_REQUIRED ON` 防止 CMake 在编译器不支持时静默降级;`CXX_EXTENSIONS OFF` 把 `-std=gnu++NN` 收成 `-std=c++NN`。configure 后检查 `compile_commands.json` 的最后一条 `-std=`。
|
|
65
66
|
- 程序 target 固定 `app`;库 target 用组件名。
|
|
66
67
|
|
|
67
68
|
## 标准与复用
|
|
68
69
|
|
|
69
|
-
C++11–C++23 的两层声明、可见性、常见错误与验证见 `../standards/cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `../assets/CompileSettings.cmake`:
|
|
70
|
+
C++11–C++23 的两层声明、可见性、常见错误与验证见 `../standards/01-cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `../assets/CompileSettings.cmake`:
|
|
70
71
|
|
|
71
72
|
```cmake
|
|
72
73
|
CompileSettings_SetCxxStandard(app PRIVATE c++23)
|
|
73
74
|
CompileSettings_SetCxxStandard(greeting PUBLIC c++20)
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `../modules/functions.md`。
|
|
77
|
+
函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `../modules/01-functions.md`。
|
|
77
78
|
|
|
78
79
|
## 警告等级
|
|
79
80
|
|
|
@@ -90,11 +91,14 @@ MSVC 分支用 `/W4`、`/permissive-`、`/WX`;其他编译器直接报错,
|
|
|
90
91
|
- 每个 target 自己声明 include、标准、编译选项、链接库;不要用全局 `include_directories()`、`add_definitions()`、`CMAKE_CXX_FLAGS` 给所有 target 加料。
|
|
91
92
|
- `target_include_directories(<target> PUBLIC|PRIVATE <dir>)`:公共头给 `PUBLIC`,私有实现目录给 `PRIVATE`。
|
|
92
93
|
- `target_compile_features(<target> PUBLIC|PRIVATE cxx_std_NN)`:只传播“至少 C++NN”的最低要求;精确 `-std` 由 `CompileSettings_SetCxxStandard` 在会编译的 target 上设置,不靠这一步锁死。
|
|
93
|
-
- `target_link_libraries(<target> PRIVATE|PUBLIC <lib>)`:实现依赖用 `PRIVATE`,接口依赖用 `PUBLIC`。
|
|
94
|
+
- `target_link_libraries(<target> PRIVATE|PUBLIC <lib>)`:实现依赖用 `PRIVATE`,接口依赖用 `PUBLIC`。CMake 只硬性要求第一个参数已创建;被链接的库可以稍后定义,CMake 会补 ordering dependency。工程约定仍是先定义后引用,避免靠隐式排序。
|
|
94
95
|
- 不要 `file(GLOB ...)`;显式列源文件,新增文件时改 CMake,构建系统才知道。`CONFIGURE_DEPENDS` 依赖构建系统每次检查目录,跨生成器行为也不完全一致,不作为工程规则。
|
|
95
96
|
- 不把 `main()` 编进库;程序只做装配和 I/O。
|
|
96
97
|
- 头文件不参与编译时,不需要 `target_sources` 列出;需要 IDE 展示时再列。
|
|
97
|
-
- 组件多起来时,一个组件一个 `CMakeLists.txt`:库放 `<component>/include` 与 `<component>/src`,程序放 `
|
|
98
|
+
- 组件多起来时,一个组件一个 `CMakeLists.txt`:库放 `<component>/include` 与 `<component>/src`,程序放 `app/include` 与 `app/src`;`app/include` 只给程序内部用,不要被库 `PUBLIC` 导出。
|
|
99
|
+
- 源文件只列在它所在目录的 target 里;子目录的程序或测试用 `target_link_libraries` 链接该 target,不写 `../other/src/*.cpp`;跨目录共用代码时,先让源目录提供可链接的 target。
|
|
100
|
+
- CMake 注释只写 target 的职责、可见性和使用条件,不写「源码留在本目录」「子目录不写 ../other/src/*.cpp」这类目录边界;源文件列表与链接关系已经表达边界。
|
|
101
|
+
- 一个 target 的配置连续成块:按 `add_*`、`target_include_directories`、`CompileSettings_SetCxxStandard`、`CompileSettings_SetWarnings`、其它 `target_*` 编译选项、`target_link_libraries`、`set_target_properties` 的顺序写;标准与警告必须相邻,`target_link_libraries` 与 `set_target_properties` 也必须相邻,中间不插其它调用。
|
|
98
102
|
- 测试 target 等出现第二个消费者时再加,不要为单个 `main()` 提前引入测试框架;测试只链接库的公共接口。
|
|
99
103
|
|
|
100
104
|
## 工程名
|
|
@@ -191,6 +195,34 @@ LinkSettings_FetchGoogleTest()
|
|
|
191
195
|
- 在 `CMakeLists.txt` 里 `execute_process` 下载依赖或改源码。
|
|
192
196
|
- 用 `CMAKE_CXX_FLAGS` 加 `-std=c++23` 之类与声明不符的标准。
|
|
193
197
|
|
|
198
|
+
## 正反例
|
|
199
|
+
|
|
200
|
+
### CMake 函数注释
|
|
201
|
+
|
|
202
|
+
**差**:
|
|
203
|
+
|
|
204
|
+
```cmake
|
|
205
|
+
#[[.rst:
|
|
206
|
+
CompileSettings_SetWarnings
|
|
207
|
+
---------------------------
|
|
208
|
+
]]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`#[[.rst:` 与 `.. command::` 只给要进 CMake 手册的模块用;`@param`、`@return` 是 C++ 的 Doxygen 标签,CMake 里不用;CMake 函数没有返回值,也不写 `:return:`。
|
|
212
|
+
|
|
213
|
+
**好**:
|
|
214
|
+
|
|
215
|
+
```cmake
|
|
216
|
+
# 给一个目标加上编译警告。
|
|
217
|
+
#
|
|
218
|
+
# 只改传入的目标。PRIVATE 不向使用方传播。
|
|
219
|
+
#
|
|
220
|
+
# :param target: 已经存在的 CMake 目标。
|
|
221
|
+
# :param visibility: 取 PRIVATE 或 INTERFACE。
|
|
222
|
+
# :keyword LEVEL: 可省略。取 basic、standard 或 strict;省略时按 standard。
|
|
223
|
+
function(CompileSettings_SetWarnings target visibility)
|
|
224
|
+
```
|
|
225
|
+
|
|
194
226
|
## 依据
|
|
195
227
|
|
|
196
228
|
- [CMake: `add_library`](https://cmake.org/cmake/help/latest/command/add_library.html):库 target 的类型与作用域。
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
<!-- 读取时机:配 CMake 或工具链时;读完能回答:测试与 CTest;预算:一次只开这一份(61 行),不自动串联。 -->
|
|
1
2
|
# 测试与 CTest
|
|
2
3
|
|
|
3
|
-
测试属于构建域:测试 target 由 `engineering` 写进 CMake
|
|
4
|
+
测试属于构建域:测试 target 由 `engineering` 写进 CMake;测试代码的写法由本文件说明,CTest 运行归 `building-cpp` 的通过检查。条文依据 GoogleTest Primer、CMake 的 `add_test` / `gtest_discover_tests` 文档与 CTest 手册,访问日期 2026-10-27。
|
|
4
5
|
|
|
5
6
|
## 先决定测什么
|
|
6
7
|
|
|
@@ -30,7 +31,7 @@ gtest_discover_tests(my_project_test
|
|
|
30
31
|
- 需要独占端口、固定文件或数据库的用例用 `RESOURCE_LOCK`;有准备/清理步骤时用 `FIXTURES_SETUP` / `FIXTURES_REQUIRED`。
|
|
31
32
|
- `--no-tests=error` 防止「0 个测试也算通过」;`--output-on-failure` 只在失败时打印输出,避免日志淹没。
|
|
32
33
|
|
|
33
|
-
##
|
|
34
|
+
## 运行顺序(building-cpp 执行)
|
|
34
35
|
|
|
35
36
|
1. 构建通过后跑 `ctest --test-dir build/<compiler> --output-on-failure --no-tests=error`。
|
|
36
37
|
2. 先跑失败用例的单条:`ctest -R <用例名> --output-on-failure`,确认失败可复现。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:编码与行尾;预算:一次只开这一份(49 行),不自动串联。 -->
|
|
1
2
|
# 编码与行尾
|
|
2
3
|
|
|
3
4
|
默认组合是 UTF-8 无 BOM、LF。机器规则以仓库根 `.gitattributes` 与 `.editorconfig` 为准,本文件只记决定、MSVC 例外与检查方法。
|
|
@@ -32,7 +33,7 @@ MSVC 默认按 BOM 判断源码编码。源码没有 BOM 时,它按当前用
|
|
|
32
33
|
在仓库根运行:
|
|
33
34
|
|
|
34
35
|
```bash
|
|
35
|
-
node "<skill-dir>/
|
|
36
|
+
node "<skill-dir>/scripts/checking-encoding.mjs" --profile portable
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
- `portable`(默认)要求所有文本文件 UTF-8 无 BOM、LF、末尾换行。
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:clang-format;预算:一次只开这一份(21 行),不自动串联。 -->
|
|
1
2
|
# clang-format
|
|
2
3
|
|
|
3
4
|
三件语言工具各管一段:`clang-format` 排版、`clang-tidy` 诊断、`clangd` 提供补全/跳转/诊断。它们都读同一份编译数据库,但职责不重叠。编辑器侧只保留 CMake Tools 作为配置、构建、运行和调试入口;C/C++ 扩展只做 `CMake: Debug` 的调试后端,不参与语言服务。
|
|
4
5
|
|
|
5
6
|
```bash
|
|
6
|
-
clang-format --dry-run --Werror src/*.cpp include/*.h tests/*.cpp
|
|
7
|
+
clang-format --dry-run --Werror src/*.cpp include/*.h app/*.cpp tests/*.cpp
|
|
7
8
|
```
|
|
8
9
|
|
|
9
10
|
- 检查用 `--dry-run --Werror`;需要自动修复时单独跑 `clang-format -i`,不要在构建脚本里悄悄改源码。
|
|
10
11
|
- 工程必须有根 `.clang-format`;缺失时先复制配置,不要回退到内置风格,回退会掩盖配置缺失。
|
|
11
|
-
- 只扫描项目源码:`src/`、`include/`、`
|
|
12
|
+
- 只扫描项目源码:`src/`、`include/`、`app/`、`tests/` 等实际存在的目录;不扫描 `build/`、第三方、生成文件。
|
|
12
13
|
- 配置文件在工程根 `.clang-format`;不要依赖用户主目录或编辑器内置配置。
|
|
13
14
|
- `BasedOnStyle: Google`、`Standard: Latest`;`c++23` 到 clang-format 23 才被接受,21 与 22 会报 `error: unknown enumerated scalar`,`Latest` 在旧版本上按该版本支持的最高标准解析。列宽、缩进与包含顺序以工程根 `.clang-format` 为准;工程显式写 `ColumnLimit` 时按工程值执行,模板资产不写 `ColumnLimit`。
|
|
15
|
+
- 构造函数初始化列表写 `PackConstructorInitializers: BinPack`:放得下时并入一行,超出列宽再按成员换行。Google 预设逐项换行,成员一多就占五六行,与「列宽内保持一行」冲突;这条只在配置里定,不在条文里规定手写位置。
|
|
14
16
|
- 格式化失败就是失败,不要用 `// clang-format off` 绕过;确需关闭时只包住无法排版的宏或表格,并写一句理由。
|
|
15
17
|
|
|
16
18
|
## 依据
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:clang-tidy 与静态检查门禁;预算:一次只开这一份(58 行),不自动串联。 -->
|
|
1
2
|
# clang-tidy 与静态检查门禁
|
|
2
3
|
|
|
3
4
|
## clang-tidy
|
|
4
5
|
|
|
5
6
|
```bash
|
|
6
7
|
clang-tidy -p build/clang \
|
|
7
|
-
--header-filter="^$(pwd -P)/(include|src|
|
|
8
|
+
--header-filter="^$(pwd -P)/(include|src|app|tests)/" \
|
|
8
9
|
--warnings-as-errors='*' \
|
|
9
|
-
src/*.cpp
|
|
10
|
+
src/*.cpp app/*.cpp tests/*.cpp
|
|
10
11
|
```
|
|
11
12
|
|
|
12
13
|
- `-p` 指向当前编译器的构建目录,读取 `compile_commands.json`。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:clangd 与编辑器;预算:一次只开这一份(91 行),不自动串联。 -->
|
|
1
2
|
# clangd 与编辑器
|
|
2
3
|
|
|
3
4
|
## clangd
|
|
@@ -63,6 +64,7 @@ Diagnostics:
|
|
|
63
64
|
],
|
|
64
65
|
"cmake.buildDirectory": "${workspaceFolder}/build/clang",
|
|
65
66
|
"cmake.generator": "Ninja",
|
|
67
|
+
"cmake.configureOnOpen": true,
|
|
66
68
|
"cmake.buildBeforeRun": true,
|
|
67
69
|
"cmake.exportCompileCommandsFile": true,
|
|
68
70
|
"cmake.debugConfig": {
|
package/skills/engineering/references/formatting/examples/{clang-format.md → 01-clang-format.md}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 读取时机:排版或工具配置时;读完能回答:正反例:clang-format;预算:一次只开这一份(38 行),不自动串联。 -->
|
|
1
2
|
# 正反例:clang-format
|
|
2
3
|
|
|
3
4
|
## 构建脚本里自动格式化
|
|
@@ -35,4 +36,4 @@ BasedOnStyle: Google
|
|
|
35
36
|
Standard: Latest
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
配置只选预设和语言版本,不重复策略;列宽、缩进、包含顺序都由 Google
|
|
39
|
+
配置只选预设和语言版本,不重复策略;列宽、缩进、包含顺序都由 Google 预设决定。需要新规则时先改技能文档并说明理由,不要在手写配置里堆本地约定。两例的差别在把策略写进配置头,不是 `ColumnLimit`;要改列宽时按工程值设置并改技能依据。
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!-- 读取时机:入口表点名或判不准时;读完能回答:每份条文的读取时机、产出与预算;预算:一次只开这一份,按需再开单份。 -->
|
|
2
|
+
# 条文索引
|
|
3
|
+
|
|
4
|
+
先读本页,再按主题或语义开一份;不要一次打开多份。
|
|
5
|
+
|
|
6
|
+
## cmake
|
|
7
|
+
|
|
8
|
+
| 文件 | 读完能回答 | 预算 |
|
|
9
|
+
| --- | --- | --- |
|
|
10
|
+
| `cmake/linking/01-libraries.md` | 链接与库边界 | 一次只开这一份(62 行),不自动串联。 |
|
|
11
|
+
| `cmake/linking/02-rpath.md` | 输出目录与 RPATH | 一次只开这一份(25 行),不自动串联。 |
|
|
12
|
+
| `cmake/linking/03-undefined-reference.md` | undefined reference 分诊 | 一次只开这一份(20 行),不自动串联。 |
|
|
13
|
+
| `cmake/linking/04-inspect.md` | 验收:file 与 ldd | 一次只开这一份(20 行),不自动串联。 |
|
|
14
|
+
| `cmake/modules/01-functions.md` | CMake 模块与函数 | 一次只开这一份(108 行),不自动串联。 |
|
|
15
|
+
| `cmake/standards/01-cxx-standard.md` | C++ 标准与 CMake | 一次只开这一份(68 行),不自动串联。 |
|
|
16
|
+
| `cmake/standards/versions.md` | C++11–C++23 各档差异 | 一次只开这一份(43 行),不自动串联。 |
|
|
17
|
+
| `cmake/standards/examples/01-standard.md` | 正反例:标准只写一半 | 一次只开这一份(19 行),不自动串联。 |
|
|
18
|
+
| `cmake/targets/01-target-rules.md` | CMake | 一次只开这一份(230 行),不自动串联。 |
|
|
19
|
+
| `cmake/targets/examples/01-rpath.md` | 正反例:共享库运行时路径 | 一次只开这一份(24 行),不自动串联。 |
|
|
20
|
+
| `cmake/testing/01-ctest.md` | 测试与 CTest | 一次只开这一份(61 行),不自动串联。 |
|
|
21
|
+
|
|
22
|
+
## formatting
|
|
23
|
+
|
|
24
|
+
| 文件 | 读完能回答 | 预算 |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `formatting/01-encoding.md` | 编码与行尾 | 一次只开这一份(49 行),不自动串联。 |
|
|
27
|
+
| `formatting/02-clang-format.md` | clang-format | 一次只开这一份(21 行),不自动串联。 |
|
|
28
|
+
| `formatting/03-clang-tidy.md` | clang-tidy 与静态检查门禁 | 一次只开这一份(58 行),不自动串联。 |
|
|
29
|
+
| `formatting/04-clangd.md` | clangd 与编辑器 | 一次只开这一份(91 行),不自动串联。 |
|
|
30
|
+
| `formatting/examples/01-clang-format.md` | 正反例:clang-format | 一次只开这一份(38 行),不自动串联。 |
|
|
31
|
+
| `formatting/examples/02-clang-tidy.md` | 正反例:clang-tidy | 一次只开这一份(43 行),不自动串联。 |
|
|
32
|
+
| `formatting/examples/03-clangd.md` | 正反例:clangd | 一次只开这一份(109 行),不自动串联。 |
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
## 通用情况
|
|
8
8
|
|
|
9
|
-
先读 `environment.json` 的 `standard`,再把它映射成两层;调整标准前先打开 `../references/cmake/standards
|
|
9
|
+
先读 `environment.json` 的 `standard`,再把它映射成两层;调整标准前先打开 `../references/cmake/standards/versions.md`,按「不能假设」「降档要改什么」逐条处理,不允许只改数字。降档还要对照 `../references/cmake/standards/index.md` 的共用矩阵确认工具链下限。
|
|
10
10
|
|
|
11
11
|
| `standard` | `target_compile_features` | `CXX_STANDARD` | 支持该特性的 CMake 下限 |
|
|
12
12
|
| --- | --- | --- | --- |
|
|
13
|
-
| `c++11` | `cxx_std_11` | `11` | 3.
|
|
14
|
-
| `c++14` | `cxx_std_14` | `14` | 3.
|
|
13
|
+
| `c++11` | `cxx_std_11` | `11` | 3.1 |
|
|
14
|
+
| `c++14` | `cxx_std_14` | `14` | 3.1 |
|
|
15
15
|
| `c++17` | `cxx_std_17` | `17` | 3.8 |
|
|
16
16
|
| `c++20` | `cxx_std_20` | `20` | 3.12 |
|
|
17
17
|
| `c++23` | `cxx_std_23` | `23` | 3.20 |
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
## 契约
|
|
28
28
|
|
|
29
29
|
- 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` / `:keyword` 标参数;不写 `#[[.rst:` 与 `.. command::`。
|
|
30
|
-
- 完整写法见 `../references/cmake/targets/rules.md`;签名留在 `function()` 那一行。
|
|
31
|
-
- 签名、警告等级与错误消息以 `../references/cmake/assets/` 和 `../references/cmake/modules/functions.md` 为准;本步不复制第二份。
|
|
30
|
+
- 完整写法见 `../references/cmake/targets/01-target-rules.md`;签名留在 `function()` 那一行。
|
|
31
|
+
- 签名、警告等级与错误消息以 `../references/cmake/assets/` 和 `../references/cmake/modules/01-functions.md` 为准;本步不复制第二份。
|
|
32
32
|
- 普通函数只改传入 target 的属性,不写全局变量、不读环境变量、不下载依赖;唯一例外是 `LinkSettings_FetchGoogleTest`,只在测试需要时调用。
|
|
33
33
|
- 先校验 target、可见性与标准,再调用 `target_*` 或 `set_target_properties`;失败用 `FATAL_ERROR`,消息带函数名与非法值。
|
|
34
34
|
|
|
35
35
|
## 退出
|
|
36
36
|
|
|
37
|
-
模块可被根文件导入且函数签名稳定后,进 `03-check.md` 跑 configure、构建与数据库核对。排版、2 空格与注释形态按 `../references/cmake/targets/rules.md`。
|
|
37
|
+
模块可被根文件导入且函数签名稳定后,进 `03-check.md` 跑 configure、构建与数据库核对。排版、2 空格与注释形态按 `../references/cmake/targets/01-target-rules.md`。
|
|
@@ -32,7 +32,7 @@ GCC 模式把目录和编译器换成 `build/gcc`、`g++`。每次检查都重
|
|
|
32
32
|
| 现象 | 回哪一步 |
|
|
33
33
|
| --- | --- |
|
|
34
34
|
| 找不到 target、链接失败、include 路径不对 | 第 1 步 |
|
|
35
|
-
| 目标标准没有生效、`-std` 与声明不一致 | 第 1 步,必要时重读 `../references/cmake/standards/cxx-standard.md` |
|
|
35
|
+
| 目标标准没有生效、`-std` 与声明不一致 | 第 1 步,必要时重读 `../references/cmake/standards/01-cxx-standard.md` |
|
|
36
36
|
| 函数参数没校验、模块重复导入、旧模块残留 | 第 2 步 |
|
|
37
37
|
| 只是 CTest 或运行失败 | 转 `building-cpp` 的通过检查 |
|
|
38
38
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- 读取时机:三份 SKILL.md 的「加载预算」或判不准加载哪一层时;读完能回答:加载预算与层表;预算:一次只开这一份(19 行),不自动串联。 -->
|
|
2
|
+
# 加载预算
|
|
3
|
+
|
|
4
|
+
三份 `SKILL.md` 共用这一页的预算与层表;技能正文只留入口,不复制本页条文。
|
|
5
|
+
|
|
6
|
+
## 预算
|
|
7
|
+
|
|
8
|
+
- 只开当前步对应的一个步骤文件;同一改动域内不同时展开两个技能的步骤。
|
|
9
|
+
- 条文只开该步点名的一份;同号案例留到下一次激活。
|
|
10
|
+
- 标准档只打开项目技能声明的那一档,没有声明时用本技能已有的新工程默认,不把其余标准档读进来。
|
|
11
|
+
- 上限:`SKILL.md` 不超过 100 行;单份 reference 不超过 240 行;一次只开一份;`references/index.md` 不超过 240 行。
|
|
12
|
+
|
|
13
|
+
## 层与加载
|
|
14
|
+
|
|
15
|
+
| 层 | 职责 | 何时加载 |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| 常驻元数据 | `name`、`description` | 会话目录常驻;正文不加载 |
|
|
18
|
+
| 技能正文 | `SKILL.md` 的适用场景、操作、步骤、入口表、完成判据 | 技能被选中时 |
|
|
19
|
+
| 步骤 | `steps/0N-*.md` 的当前步骤流程 | 进入该步时只开同号一份 |
|
|
20
|
+
| 条文与案例 | `references/` 的规则、案例与术语 | 入口表或步骤点名时;判不准、冲突或排错时按需 |
|
package/skills/{developing-cpp/references/editing/01-edit-operations.md → shared/operations.md}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- 读取时机:判操作、改结构或规则冲突时;读完能回答:变更模型;预算:一次只开这一份(78 行),不自动串联。 -->
|
|
1
2
|
# 变更模型
|
|
2
3
|
|
|
3
4
|
三个技能共用这一份模型。操作决定从哪一步进、这次改动的范围多大;域决定改动落在哪一层。操作不是域,域也不是步骤。
|
|
@@ -10,6 +11,10 @@
|
|
|
10
11
|
| 改写 | 可观察行为与契约不变,组织、顺序或位置不对 | 移动、删除、换序、重写块段;保留事实与论证线 | 新增事实、数字、命令、结论或行为;改变否定、条件、范围、时间、归属 |
|
|
11
12
|
| 润色 | 只改措辞、命名或注释 | 删复述、换词、拆句、统一术语 | 改结构、改事实、加句子或加信息;把可能或通常改成确定 |
|
|
12
13
|
|
|
14
|
+
## 操作判定
|
|
15
|
+
|
|
16
|
+
先问这次改动是否改变读者理解的内容:改变内容 → 写作;不改变内容但改变组织、顺序或位置 → 改写;内容与结构都不变,只改措辞、命名或注释 → 润色。三份 `SKILL.md` 的「三种操作」表前都指到这一节,表只写本技能的入口步骤,不重复判据。
|
|
17
|
+
|
|
13
18
|
## 判不准时
|
|
14
19
|
|
|
15
20
|
按顺序问,第一问为是就是写作:
|
|
@@ -41,7 +46,7 @@
|
|
|
41
46
|
| 版式 | 它长什么样? | 缩进、行宽、空行、注释符号、标签格式 | 标识符、字符串、命令、语义 |
|
|
42
47
|
| 措辞 | 这句话是否准确、必要、可读? | 命名、用词、句式、复述、术语统一 | 结构、事实、段落顺序、信息量 |
|
|
43
48
|
|
|
44
|
-
四域按「内容 → 结构 → 版式 → 措辞」推进。前一层没落定,不进入下一层;后一层发现前一层没做完,退回那一层,不在当前层补。`
|
|
49
|
+
四域按「内容 → 结构 → 版式 → 措辞」推进。前一层没落定,不进入下一层;后一层发现前一层没做完,退回那一层,不在当前层补。`rule-priority.md` 的五级次序是冲突时的判据:行为与契约 > 结构 > 清晰 > 一致 > 形式。
|
|
45
50
|
|
|
46
51
|
## 跨技能交接
|
|
47
52
|
|
|
@@ -71,5 +76,4 @@
|
|
|
71
76
|
3. 事实有没有变:有没有新增数字、命令、结论、引文,或把「可能」「通常」改成确定?
|
|
72
77
|
4. 边界写正了吗:有没有「不检查…」清单?前置条件是否写成「调用方保证…」「仅接受…」或 `@pre`?
|
|
73
78
|
5. 原样保留了吗:术语、命令、标识符、路径、URL 与围栏内容是否未被改写?
|
|
74
|
-
6. 次序守住了吗:前一层是否已落定并经检查,后一层才开始?冲突是否按 `
|
|
75
|
-
|
|
79
|
+
6. 次序守住了吗:前一层是否已落定并经检查,后一层才开始?冲突是否按 `rule-priority.md` 判?
|
package/skills/{developing-cpp/references/editing/02-rule-priority.md → shared/rule-priority.md}
RENAMED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
<!-- 读取时机:判操作、改结构或规则冲突时;读完能回答:规则冲突时的优先级;预算:一次只开这一份(38 行),不自动串联。 -->
|
|
1
2
|
# 规则冲突时的优先级
|
|
2
3
|
|
|
3
4
|
源码规则不是同一层的检查表。两条规则冲突时,先保住更高层,再谈低层的「更短」「更统一」「更整齐」。
|
|
4
5
|
|
|
5
|
-
本表管写作内部的取舍顺序;三种操作与四个域的先后见 `
|
|
6
|
+
本表管写作内部的取舍顺序;三种操作与四个域的先后见 `operations.md`。
|
|
6
7
|
|
|
7
8
|
| 级别 | 保住什么 | 典型判断 | 冲突时让位给谁 |
|
|
8
9
|
| --- | --- | --- | --- |
|
|
@@ -12,6 +13,12 @@
|
|
|
12
13
|
| 4 一致 | 同类声明用同一种句式、位置和术语 | 两个成员的注释是否都在说同一类事实? | 让位给行为、结构、清晰;高于形式 |
|
|
13
14
|
| 5 形式 | 行宽、缩进、空行、符号 | 这行能不能再短一点? | 前四级都通过后才动 |
|
|
14
15
|
|
|
16
|
+
## 来源效力
|
|
17
|
+
|
|
18
|
+
规则依据的效力顺序是 ISO C++ 标准、Google C++ Style、Stack Overflow。标准定义语言语义,Google 规定本工作流采用的工程风格,Stack Overflow 只补例子与常见误解;三者冲突时,前面的覆盖后面的。
|
|
19
|
+
|
|
20
|
+
已写明的局部偏离高于 Google 对应条款,但不得越过 ISO 标准语义。先读本页和 `02-initialization.md` 这类专项页,再按 Google 原文补齐未覆盖的部分。新增或改写的依据节按 Stack Overflow、Google、ISO 的顺序书写,先给可读解释,再落到权威条文。
|
|
21
|
+
|
|
15
22
|
## 常见冲突
|
|
16
23
|
|
|
17
24
|
- **注释更短 vs 契约完整**:删掉构造后置条件、参数范围或失败方式换来的短,不算润色;先补回契约,再压句子。
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# 推荐扩展
|
|
2
|
-
|
|
3
|
-
只在工程已经有 `.vscode/` 时读本页;从当前目录向上到 git 根都没有 `.vscode/` 时,不打开本页,也不新建目录。新工程从 `../../assets/config/.vscode/extensions.json` 复制时除外。
|
|
4
|
-
|
|
5
|
-
## 三个角色
|
|
6
|
-
|
|
7
|
-
| 扩展 | 负责 | 不负责 |
|
|
8
|
-
| --- | --- | --- |
|
|
9
|
-
| `llvm-vs-code-extensions.vscode-clangd` | 补全、跳转、诊断、格式化 | 配置与构建 |
|
|
10
|
-
| `ms-vscode.cmake-tools` | 配置、构建、运行、调试入口 | 语言服务 |
|
|
11
|
-
| `ms-vscode.cpptools` | 只作为 `CMake: Debug` 的调试后端 | IntelliSense 与格式化(关闭) |
|
|
12
|
-
|
|
13
|
-
不要同时开两套语言服务;C/C++ 扩展的 IntelliSense 必须关闭,否则会和 clangd 抢编译数据库。
|
|
14
|
-
|
|
15
|
-
## 对照现有文件
|
|
16
|
-
|
|
17
|
-
1. 读工程根 `.vscode/extensions.json`;已有推荐只补缺,不重排、不删除。
|
|
18
|
-
2. 旧工程只写了 C/C++ 扩展时,加 clangd 与 CMake Tools,并在设置里关掉 IntelliSense,理由写在提交说明里。
|
|
19
|
-
3. 不写 `tasks.json` 或 `launch.json`;配置、构建、运行和调试都从 CMake Tools 进入,构建命令仍以 `running-build.sh` 为准。
|
|
20
|
-
4. 模板在 `../../assets/config/.vscode/extensions.json`,只作为新工程的起点;工程已有文件时不复制整份覆盖。
|
|
21
|
-
|
|
22
|
-
下一步:扩展对齐后,读 [02-settings.md](02-settings.md) 接线设置。
|
|
23
|
-
|
|
24
|
-
## 依据
|
|
25
|
-
|
|
26
|
-
- [clangd: Editor Plugins](https://clangd.llvm.org/installation#editor-plugins):VS Code 的 clangd 扩展与语言服务。
|
|
27
|
-
- [CMake Tools for VS Code](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/README.md):配置、构建、调试入口。
|
|
28
|
-
- [VS Code: Extension Recommendations](https://code.visualstudio.com/docs/editor/extension-marketplace#_workspace-recommended-extensions):`extensions.json` 的 `recommendations`。
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# 正反例:布尔查询只写检查什么
|
|
2
|
-
|
|
3
|
-
完整写法:
|
|
4
|
-
|
|
5
|
-
```cpp
|
|
6
|
-
/// 检查指定坐标上的棋盘方格是否为空。
|
|
7
|
-
///
|
|
8
|
-
/// @param pos 待检查的坐标。
|
|
9
|
-
///
|
|
10
|
-
/// @return 坐标在棋盘内且该格为空时返回 true;越界或该格是 X 或 O 时返回 false。
|
|
11
|
-
[[nodiscard]] bool IsSquareEmpty(Position pos) const;
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
布尔查询的第一句写「检查…是否…」,`@return` 写成立与不成立的条件;能力边界不写成否定清单,调用方要满足的条件用正向限定或 `@pre`。
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# 正反例:实现注释
|
|
2
|
-
|
|
3
|
-
实现注释只写本层为什么停在这里;声明注释、文件头与配置注释见 `references/comments/examples/` 里的 `declaration-file.md`、`declaration-class.md` 等案例。
|
|
4
|
-
|
|
5
|
-
**差**:
|
|
6
|
-
|
|
7
|
-
```cpp
|
|
8
|
-
// 遍历所有空格
|
|
9
|
-
for (const auto& pos : empty_squares) {
|
|
10
|
-
// 尝试落子
|
|
11
|
-
const bool wins = game.PreviewWin(pos, state) == WinPreviewResult::kWouldWin;
|
|
12
|
-
// 如果能赢
|
|
13
|
-
if (wins) {
|
|
14
|
-
// 返回这次落子的位置
|
|
15
|
-
return pos;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
每行都在复述代码。
|
|
21
|
-
|
|
22
|
-
**好**:
|
|
23
|
-
|
|
24
|
-
```cpp
|
|
25
|
-
PlaceResult Game::Place(Move move) {
|
|
26
|
-
// 检查对局是否仍在进行。
|
|
27
|
-
if (GetResult() != GameResult::kInProgress) {
|
|
28
|
-
return PlaceResult::kFinishedGame;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 检查落子玩家是否为当前玩家。
|
|
32
|
-
if (current_player_ != move.player) {
|
|
33
|
-
return PlaceResult::kInvalidPlayer;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 检查要写入的值是否为空。
|
|
37
|
-
const SquareValue target_square_value = PlayerToSquareValue(move.player);
|
|
38
|
-
if (target_square_value == SquareValue::kEmpty) {
|
|
39
|
-
return PlaceResult::kEmptySquare;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 检查目标方格是否为空。
|
|
43
|
-
const Square target_square = board_.GetSquare(move.position);
|
|
44
|
-
if (!target_square.IsEmpty()) {
|
|
45
|
-
return PlaceResult::kOccupiedSquare;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
current_player_ = PlayerToOpponent(current_player_);
|
|
49
|
-
board_.SetSquare(move.position, target_square_value);
|
|
50
|
-
history_.push_back(move);
|
|
51
|
-
return PlaceResult::kPlaced;
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
每一条拒绝各写一条独立 `if`,在判定处用一句「检查…是否…」写这一支在检查什么;结果由分支里的 `return` 表达,不再复述「没有写入」「按失败返回」。局部值由上一行赋值取出、赋值与上一个阶段之间又有空行时,注释写在赋值那一行上方,说明赋值与紧随其后的分支这整块,`if` 上不再重复。`//` 里的枚举值不包反引号。分支的完整规则见 `references/comments/comment-rules.md` 的「实现」节。
|
|
56
|
-
|
|
57
|
-
**好(多条件)**:
|
|
58
|
-
|
|
59
|
-
```cpp
|
|
60
|
-
std::array<SquareValue, 3> values{};
|
|
61
|
-
for (std::size_t i = 0; i < line.size(); ++i) {
|
|
62
|
-
values[i] = board_.GetSquare(line[i]).GetValue();
|
|
63
|
-
}
|
|
64
|
-
// 检查第一个方格是否有值,再核对三个方格的取值是否相同。
|
|
65
|
-
if (values[0] != SquareValue::kEmpty && values[0] == values[1] && values[1] == values[2]) {
|
|
66
|
-
return values[0] == SquareValue::kX ? GameResult::kXWin : GameResult::kOWin;
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
多条件判断按代码的判定顺序写:先确认的条件在前,后核对的在后;结果由分支里的 `return` 表达,不在注释里重复。三个同类取值存进 `values` 数组并按下标读取,不写 `value0`、`value1`、`value2`。
|
|
71
|
-
|
|
72
|
-
**好(成功路径)**:
|
|
73
|
-
|
|
74
|
-
```cpp
|
|
75
|
-
// 落子成功,记录这一步并轮到对方。
|
|
76
|
-
history_.push_back(move);
|
|
77
|
-
current_player_ = PlayerToOpponent(current_player_);
|
|
78
|
-
return GetResult();
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
成功路径有多步状态更新时,用一句阶段注释概括整段;不在每一步上方逐行解释 `push_back` 与赋值。
|