@chengzhao-dev/dsh-cpp-workflow 0.7.1 → 0.7.4

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.
Files changed (175) hide show
  1. package/README.en.md +16 -10
  2. package/README.md +16 -10
  3. package/cordis.patch.yml +6 -6
  4. package/lib/client.js +3 -3
  5. package/lib/comment-policy.js +1 -1
  6. package/lib/index.js +45 -37
  7. package/lib/workspace.js +10 -17
  8. package/package.json +9 -3
  9. package/skills/building-cpp/SKILL.md +17 -17
  10. package/skills/building-cpp/assets/templates/projects/common/running-build.sh +0 -0
  11. package/skills/building-cpp/examples/environment.md +4 -3
  12. package/skills/building-cpp/references/{build-script.md → 01-build-script.md} +4 -3
  13. package/skills/building-cpp/references/{environment.md → 02-environment.md} +3 -2
  14. package/skills/building-cpp/scripts/checking-environment.mjs +11 -13
  15. package/skills/building-cpp/steps/01-build.md +4 -3
  16. package/skills/building-cpp/steps/02-tooling.md +12 -12
  17. package/skills/building-cpp/steps/03-check.md +5 -5
  18. package/skills/building-cpp/{project/vscode/02-settings.md → steps/04-vscode.md} +24 -6
  19. package/skills/developing-cpp/SKILL.md +21 -18
  20. package/skills/developing-cpp/references/comments/{comment-rules.md → 01-comment-rules.md} +81 -64
  21. package/skills/developing-cpp/references/comments/{comment-style.md → 02-style.md} +16 -18
  22. package/skills/developing-cpp/references/comments/examples/{declaration-class.md → 01-declaration-class.md} +16 -16
  23. package/skills/developing-cpp/references/comments/examples/{declaration-constructor.md → 02-declaration-constructor.md} +3 -2
  24. package/skills/developing-cpp/references/comments/examples/03-declaration-enum.md +48 -0
  25. package/skills/developing-cpp/references/comments/examples/{declaration-file.md → 04-declaration-file.md} +6 -5
  26. package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +116 -0
  27. package/skills/developing-cpp/references/comments/examples/{declaration-member.md → 06-declaration-member.md} +4 -3
  28. package/skills/developing-cpp/references/comments/examples/07-declaration-predicate.md +15 -0
  29. package/skills/developing-cpp/references/comments/examples/{declaration-struct.md → 08-declaration-struct.md} +4 -3
  30. package/skills/developing-cpp/references/comments/examples/09-implementation-body.md +95 -0
  31. package/skills/developing-cpp/references/comments/examples/10-implementation-todo.md +17 -0
  32. package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +93 -0
  33. package/skills/developing-cpp/references/design/{project-design.md → 01-project-design.md} +21 -17
  34. package/skills/developing-cpp/references/design/examples/{behavior-sentence.md → 01-behavior-sentence.md} +1 -0
  35. package/skills/developing-cpp/references/design/examples/{coordinate-table.md → 02-coordinate-table.md} +4 -3
  36. package/skills/developing-cpp/references/design/examples/{header-place.md → 03-header-place.md} +2 -1
  37. package/skills/developing-cpp/references/design/examples/{library-boundary.md → 04-library-boundary.md} +1 -0
  38. package/skills/developing-cpp/references/design/examples/{library-split.md → 05-library-split.md} +1 -0
  39. package/skills/developing-cpp/references/design/examples/06-move-result.md +42 -0
  40. package/skills/developing-cpp/references/design/examples/07-preview-read.md +37 -0
  41. package/skills/developing-cpp/references/design/session-layer.md +89 -0
  42. package/skills/developing-cpp/references/exceptions/{throw-rules.md → 01-exception-rules.md} +56 -61
  43. package/skills/developing-cpp/references/exceptions/examples/{throw-boundary.md → 01-throw-boundary.md} +1 -0
  44. package/skills/developing-cpp/references/exceptions/examples/{throw-build-mode.md → 02-throw-build-mode.md} +5 -4
  45. package/skills/developing-cpp/references/exceptions/examples/{throw-catch.md → 03-throw-catch.md} +1 -0
  46. package/skills/developing-cpp/references/exceptions/examples/{throw-destructor.md → 04-throw-destructor.md} +1 -0
  47. package/skills/developing-cpp/references/exceptions/examples/{throw-format.md → 05-throw-format.md} +1 -0
  48. package/skills/developing-cpp/references/exceptions/examples/{throw-message.md → 06-throw-message.md} +10 -1
  49. package/skills/developing-cpp/references/exceptions/examples/{throw-when.md → 07-throw-when.md} +1 -0
  50. package/skills/developing-cpp/references/index.md +132 -0
  51. package/skills/developing-cpp/references/language/glossary/{language-terms.md → 01-language-terms.md} +3 -2
  52. package/skills/developing-cpp/references/language/language-basics/01-objects.md +2 -1
  53. package/skills/developing-cpp/references/language/language-basics/02-initialization.md +2 -1
  54. package/skills/developing-cpp/references/language/language-basics/03-deduction.md +1 -0
  55. package/skills/developing-cpp/references/language/language-basics/04-const.md +5 -4
  56. package/skills/developing-cpp/references/language/language-basics/05-expressions.md +13 -4
  57. package/skills/developing-cpp/references/language/language-basics/06-functions.md +4 -1
  58. package/skills/developing-cpp/references/language/language-basics/07-classes.md +1 -0
  59. package/skills/developing-cpp/references/language/language-basics/08-raii.md +1 -0
  60. package/skills/developing-cpp/references/language/language-basics/09-templates.md +1 -0
  61. package/skills/developing-cpp/references/language/language-basics/{10-checklist.md → 10-language-checklist.md} +2 -0
  62. package/skills/developing-cpp/references/language/performance/01-measure.md +1 -0
  63. package/skills/developing-cpp/references/language/performance/02-complexity.md +1 -0
  64. package/skills/developing-cpp/references/language/performance/03-memory.md +1 -0
  65. package/skills/developing-cpp/references/language/performance/04-undefined-behavior.md +1 -0
  66. package/skills/developing-cpp/references/language/performance/05-pitfalls.md +1 -0
  67. package/skills/developing-cpp/references/language/performance/06-false-optimizations.md +1 -0
  68. package/skills/developing-cpp/references/language/performance/07-checklist.md +1 -0
  69. package/skills/developing-cpp/references/language/standard-library/01-containers.md +1 -0
  70. package/skills/developing-cpp/references/language/standard-library/02-access.md +2 -1
  71. package/skills/developing-cpp/references/language/standard-library/03-iteration.md +1 -0
  72. package/skills/developing-cpp/references/language/standard-library/04-algorithms.md +1 -0
  73. package/skills/developing-cpp/references/language/standard-library/05-string.md +1 -0
  74. package/skills/developing-cpp/references/language/standard-library/06-format.md +17 -6
  75. package/skills/developing-cpp/references/language/standard-library/07-time.md +1 -0
  76. package/skills/developing-cpp/references/language/standard-library/08-random.md +2 -0
  77. package/skills/developing-cpp/references/language/standard-library/09-files.md +1 -0
  78. package/skills/developing-cpp/references/language/standard-library/{10-checklist.md → 10-library-checklist.md} +1 -0
  79. package/skills/developing-cpp/references/language/value-types/01-width.md +1 -0
  80. package/skills/developing-cpp/references/language/value-types/02-signed.md +1 -0
  81. package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +1 -0
  82. package/skills/developing-cpp/references/language/value-types/04-enum.md +3 -2
  83. package/skills/developing-cpp/references/language/value-types/05-strong-type.md +1 -0
  84. package/skills/developing-cpp/references/language/value-types/06-const-method.md +1 -0
  85. package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +2 -1
  86. package/skills/developing-cpp/references/language/value-types/08-comparison.md +2 -1
  87. package/skills/developing-cpp/references/language/value-types/09-subscript.md +2 -1
  88. package/skills/developing-cpp/references/language/value-types/10-float-bool.md +1 -0
  89. package/skills/developing-cpp/references/language/value-types/11-checklist.md +1 -0
  90. package/skills/developing-cpp/references/layout/01-source-layout.md +3 -3
  91. package/skills/developing-cpp/references/layout/02-file-template.md +10 -9
  92. package/skills/developing-cpp/references/layout/03-declaration-order.md +25 -12
  93. package/skills/developing-cpp/references/naming/01-identifier-names.md +128 -0
  94. package/skills/developing-cpp/references/naming/examples/01-naming-accessor.md +29 -0
  95. package/skills/developing-cpp/references/naming/examples/02-naming-basic.md +4 -0
  96. package/skills/developing-cpp/references/naming/examples/{naming-current-prefix.md → 03-naming-current-prefix.md} +1 -0
  97. package/skills/developing-cpp/references/naming/examples/04-naming-local.md +46 -0
  98. package/skills/developing-cpp/references/naming/examples/{naming-lookup.md → 05-naming-lookup.md} +2 -1
  99. package/skills/developing-cpp/references/naming/examples/06-naming-lower-layer.md +46 -0
  100. package/skills/developing-cpp/references/naming/examples/{naming-multiple-return.md → 07-naming-multiple-return.md} +1 -0
  101. package/skills/developing-cpp/references/naming/examples/08-naming-player-value.md +16 -0
  102. package/skills/developing-cpp/references/naming/examples/09-naming-predicate.md +19 -0
  103. package/skills/developing-cpp/references/naming/examples/{naming-rename.md → 10-naming-rename.md} +1 -0
  104. package/skills/developing-cpp/references/naming/examples/{naming-responsibility.md → 11-naming-responsibility.md} +1 -0
  105. package/skills/developing-cpp/references/naming/examples/{naming-role.md → 12-naming-role.md} +2 -1
  106. package/skills/developing-cpp/references/naming/examples/13-naming-state-change.md +70 -0
  107. package/skills/developing-cpp/references/naming/glossary/01-naming-terms.md +27 -0
  108. package/skills/developing-cpp/references/naming/glossary/02-position.md +24 -0
  109. package/skills/developing-cpp/references/naming/glossary/03-selection.md +23 -0
  110. package/skills/developing-cpp/references/naming/glossary/04-square.md +48 -0
  111. package/skills/developing-cpp/references/naming/glossary/05-scoring.md +27 -0
  112. package/skills/developing-cpp/references/naming/glossary/06-difficulty.md +26 -0
  113. package/skills/developing-cpp/references/style/{google-cpp-style.md → 01-google-cpp-style.md} +16 -9
  114. package/skills/developing-cpp/scripts/checking-comments.mjs +116 -9
  115. package/skills/developing-cpp/scripts/checking-declaration-order.mjs +27 -1
  116. package/skills/developing-cpp/steps/01-behavior.md +5 -5
  117. package/skills/developing-cpp/steps/02-boundary.md +6 -6
  118. package/skills/developing-cpp/steps/03-declaration.md +7 -7
  119. package/skills/developing-cpp/steps/04-implementation.md +16 -16
  120. package/skills/engineering/SKILL.md +19 -19
  121. package/skills/engineering/references/cmake/linking/01-libraries.md +7 -4
  122. package/skills/engineering/references/cmake/linking/02-rpath.md +1 -0
  123. package/skills/engineering/references/cmake/linking/03-undefined-reference.md +3 -2
  124. package/skills/engineering/references/cmake/linking/04-inspect.md +1 -1
  125. package/skills/engineering/references/cmake/modules/{functions.md → 01-functions.md} +4 -3
  126. package/skills/engineering/references/cmake/{standard/cxx-standard.md → standards/01-cxx-standard.md} +2 -1
  127. package/skills/engineering/references/cmake/{standard/examples/standard.md → standards/examples/01-standard.md} +2 -1
  128. package/skills/engineering/references/cmake/{standard/standards/README.md → standards/index.md} +22 -21
  129. package/skills/engineering/references/cmake/standards/versions.md +44 -0
  130. package/skills/engineering/references/cmake/targets/{rules.md → 01-target-rules.md} +34 -5
  131. package/skills/engineering/references/cmake/targets/examples/{rpath.md → 01-rpath.md} +1 -0
  132. package/skills/engineering/references/cmake/testing/{ctest.md → 01-ctest.md} +4 -3
  133. package/skills/engineering/references/formatting/01-encoding.md +2 -1
  134. package/skills/engineering/references/formatting/02-clang-format.md +4 -3
  135. package/skills/engineering/references/formatting/03-clang-tidy.md +3 -2
  136. package/skills/engineering/references/formatting/04-clangd.md +2 -0
  137. package/skills/engineering/references/formatting/examples/{clang-format.md → 01-clang-format.md} +2 -1
  138. package/skills/engineering/references/formatting/examples/{clang-tidy.md → 02-clang-tidy.md} +1 -0
  139. package/skills/engineering/references/formatting/examples/{clangd.md → 03-clangd.md} +1 -0
  140. package/skills/engineering/references/index.md +32 -0
  141. package/skills/engineering/{references/formatting/scripts → scripts}/checking-encoding.mjs +6 -7
  142. package/skills/engineering/steps/01-targets.md +5 -4
  143. package/skills/engineering/steps/02-modules.md +3 -3
  144. package/skills/engineering/steps/03-check.md +3 -2
  145. package/skills/shared/budget.md +20 -0
  146. package/skills/{developing-cpp/references/editing/01-edit-operations.md → shared/operations.md} +8 -4
  147. package/skills/{developing-cpp/references/editing/02-rule-priority.md → shared/rule-priority.md} +2 -1
  148. package/skills/building-cpp/project/vscode/01-extensions.md +0 -28
  149. package/skills/developing-cpp/references/comments/examples/declaration-enum.md +0 -48
  150. package/skills/developing-cpp/references/comments/examples/declaration-function.md +0 -127
  151. package/skills/developing-cpp/references/comments/examples/declaration-predicate.md +0 -14
  152. package/skills/developing-cpp/references/comments/examples/implementation-body.md +0 -64
  153. package/skills/developing-cpp/references/comments/examples/implementation-todo.md +0 -16
  154. package/skills/developing-cpp/references/comments/glossary/comment-terms.md +0 -93
  155. package/skills/developing-cpp/references/design/examples/move-result.md +0 -39
  156. package/skills/developing-cpp/references/design/examples/preview-read.md +0 -40
  157. package/skills/developing-cpp/references/naming/examples/naming-accessor.md +0 -17
  158. package/skills/developing-cpp/references/naming/examples/naming-basic.md +0 -3
  159. package/skills/developing-cpp/references/naming/examples/naming-lower-layer.md +0 -39
  160. package/skills/developing-cpp/references/naming/examples/naming-player-value.md +0 -16
  161. package/skills/developing-cpp/references/naming/examples/naming-predicate.md +0 -18
  162. package/skills/developing-cpp/references/naming/examples/naming-state-change.md +0 -57
  163. package/skills/developing-cpp/references/naming/identifier-names.md +0 -104
  164. package/skills/engineering/references/cmake/standard/standards/c++11/README.md +0 -50
  165. package/skills/engineering/references/cmake/standard/standards/c++14/README.md +0 -48
  166. package/skills/engineering/references/cmake/standard/standards/c++17/README.md +0 -50
  167. package/skills/engineering/references/cmake/standard/standards/c++20/README.md +0 -50
  168. package/skills/engineering/references/cmake/standard/standards/c++23/README.md +0 -50
  169. package/skills/engineering/references/cmake/targets/examples/glob.md +0 -22
  170. package/skills/engineering/references/cmake/targets/examples/target.md +0 -156
  171. /package/skills/engineering/references/cmake/{standard/standards → standards}/c++11/cmake-snippet.cmake +0 -0
  172. /package/skills/engineering/references/cmake/{standard/standards → standards}/c++14/cmake-snippet.cmake +0 -0
  173. /package/skills/engineering/references/cmake/{standard/standards → standards}/c++17/cmake-snippet.cmake +0 -0
  174. /package/skills/engineering/references/cmake/{standard/standards → standards}/c++20/cmake-snippet.cmake +0 -0
  175. /package/skills/engineering/references/cmake/{standard/standards → standards}/c++23/cmake-snippet.cmake +0 -0
@@ -1,40 +0,0 @@
1
- # 正反例:推演一步读原数据
2
-
3
- **差**:先复制整个棋盘,再在副本上落子,最后判断成线;调用方看不出副本只是中间量,还要重复处理落子失败。
4
-
5
- ```cpp
6
- Board hypothetical = *this;
7
- const Square::PlaceResult placed = hypothetical.Place(pos, value);
8
- if (placed != Square::PlaceResult::kSuccess) {
9
- return WinPreviewResult::kInvalidPlace;
10
- }
11
- return hypothetical.HasLine(value) ? WinPreviewResult::kWouldWin
12
- : WinPreviewResult::kWouldNotWin;
13
- ```
14
-
15
- **好**:判断「这一格换成某种棋子后会不会成线」不需要第二份棋盘。越界、空格、已占用交给 `CheckPlaceable` 统一返回原因;通过之后只在包含该坐标的线上把这一格算作 `value`,其余格子读原棋盘。
16
-
17
- ```cpp
18
- WinPreviewResult Board::PreviewWin(Position pos, SquareValue value) const {
19
- if (CheckPlaceable(pos, value) != Square::PlaceResult::kSuccess) {
20
- return WinPreviewResult::kInvalidPlace;
21
- }
22
-
23
- const auto matches = [&](Position cell) {
24
- if (cell.row == pos.row && cell.col == pos.col) {
25
- return true;
26
- }
27
- return squares_.at(cell.row).at(cell.col) == value;
28
- };
29
-
30
- const bool completes = std::ranges::any_of(kLines, [&](const auto& line) {
31
- const bool contains = std::ranges::find_if(line, [&](Position cell) {
32
- return cell.row == pos.row && cell.col == pos.col;
33
- }) != line.end();
34
- return contains && std::ranges::all_of(line, matches);
35
- });
36
- return completes ? WinPreviewResult::kWouldWin : WinPreviewResult::kWouldNotWin;
37
- }
38
- ```
39
-
40
- 先用 `IsInRange` 拒绝越界,再用 `at()` 读取;失败路径不碰数组,`noexcept` 也就不再成立。
@@ -1,17 +0,0 @@
1
- # 正反例:访问器
2
-
3
- **差**:
4
-
5
- ```cpp
6
- Order current_order() const; // 成员名直接当函数名
7
- void set_current_order(Order order);
8
- ```
9
-
10
- **好**:
11
-
12
- ```cpp
13
- [[nodiscard]] Order GetCurrentOrder() const;
14
- void AdvanceOrder(); // 领域动作,不是 setter
15
- ```
16
-
17
- 查询统一 `Get` + PascalCase;修改用领域动词。只有真正需要替换值时,才考虑 `Set` 形式,并说明为什么不是动作。
@@ -1,3 +0,0 @@
1
- # 正反例:基本规则
2
-
3
- 大小写、前缀与成员尾随 `_` 的规则表见 `references/naming/identifier-names.md`;下面只收需要语境才能判断的例子。
@@ -1,39 +0,0 @@
1
- # 正反例:下层类型不要借用上层词汇
2
-
3
- **差**:`Board` 定义并返回 `GameResult`。
4
-
5
- ```cpp
6
- // board.h:棋盘定义了对局结果
7
- enum class GameResult : std::uint8_t {
8
- kInProgress = 0,
9
- kXWon = 1,
10
- kOWon = 2,
11
- kDrawn = 3,
12
- };
13
-
14
- class Board {
15
- public:
16
- [[nodiscard]] GameResult GetGameResult() const;
17
- };
18
- ```
19
-
20
- **为什么错**:`Game` 组合 `Board`,调用方向是 `Game -> Board`;`Board` 不知道「一局对局」的生命周期,却用 `GameResult` 命名自己的返回值。读者会以为棋盘负责对局状态,`Game` 里再出现同名概念时也无法区分。**下层类型不出现上层类型名。**
21
-
22
- **好**:
23
-
24
- ```cpp
25
- // board.h:棋盘只回答棋盘自己的状态
26
- enum class BoardStatus : std::uint8_t {
27
- kInProgress = 0,
28
- kXWon = 1,
29
- kOWon = 2,
30
- kDrawn = 3,
31
- };
32
-
33
- class Board {
34
- public:
35
- [[nodiscard]] BoardStatus GetStatus() const;
36
- };
37
- ```
38
-
39
- `Board` 的返回值用 `BoardStatus`;`Game` 需要「对局结果」时在 `Game` 层组合或另起名字,不把 `Game` 的词汇塞进 `Board`。`GameResult`、`GameState`、`PlayerMove` 这类「上层前缀 + 下层类型」都按反例处理。
@@ -1,16 +0,0 @@
1
- # 正反例:玩家与格子取值
2
-
3
- **差**:
4
-
5
- ```cpp
6
- Player OtherPlayer(Player player); // 另一端是谁不明显
7
- ```
8
-
9
- **好**:
10
-
11
- ```cpp
12
- [[nodiscard]] constexpr Player GetOpponent(Player player) noexcept;
13
- [[nodiscard]] constexpr SquareValue PlayerToSquareValue(Player player) noexcept;
14
- ```
15
-
16
- 玩家互换用 `GetOpponent`;玩家换成格子取值用 `PlayerToSquareValue`。查询名与返回类型一致:返回 `Player` 写 `GetCurrentPlayer`,返回 `SquareValue` 写 `GetCurrentValue`。
@@ -1,18 +0,0 @@
1
- # 正反例:谓词与 Lambda
2
-
3
- **差**:
4
-
5
- ```cpp
6
- bool valid(int value);
7
- auto check = [](const Task& task) { return task.done; };
8
- ```
9
-
10
- **好**:
11
-
12
- ```cpp
13
- [[nodiscard]] bool IsValid(int value);
14
- auto is_done = [](const Task& task) { return task.done; };
15
- auto has_owner = [](const Task& task) { return !task.owner.empty(); };
16
- ```
17
-
18
- 返回 `bool` 的自由函数用 `Is` / `Has` / `Can` / `Should` 开头;Lambda 用 snake_case 的 `is_` / `has_` / `can_`,读起来像条件。
@@ -1,57 +0,0 @@
1
- # 正反例:状态变更:动作与结果枚举
2
-
3
- **差**:
4
-
5
- ```cpp
6
- enum class SetStateResult : std::uint8_t {
7
- kUpdated = 0,
8
- kEmptyInput = 1,
9
- kOccupied = 2,
10
- };
11
-
12
- class Square {
13
- public:
14
- SetStateResult SetState(SquareValue state);
15
- void ResetState();
16
- };
17
- ```
18
-
19
- **好**:
20
-
21
- ```cpp
22
- enum class PlaceResult : std::uint8_t {
23
- kSuccess = 0,
24
- kIgnored = 1,
25
- kOccupied = 2,
26
- };
27
-
28
- class Square {
29
- public:
30
- [[nodiscard]] bool IsEmpty() const;
31
- [[nodiscard]] SquareValue GetValue() const;
32
- [[nodiscard]] PlaceResult Place(SquareValue value);
33
- void Clear();
34
- };
35
- ```
36
-
37
- `SetState` / `SetStateResult` 把存储动作写进 API 和结果名;领域动作是 `Place`,一次写入的结果叫 `PlaceResult`,取值写结果类别(成功、失败)。`Clear` 比 `ResetState` 短,且和 `Place` 成对。
38
-
39
- 改名按这个顺序做,每一步都能编译:
40
-
41
- | 旧名 | 新名 | 理由 |
42
- | --- | --- | --- |
43
- | `SetStateResult` | `PlaceResult` | 结果对象 + Result,和 `Place` 放在一起 |
44
- | `SetState` | `Place` | 领域动作,不暴露「设状态」 |
45
- | `ResetState` | `Clear` | 领域动作,和 `Place` 成对 |
46
- | `kEmptyInput` | `kIgnored` | 失败值写原因,和 `kOccupied`/`kSuccess` 同一句式 |
47
-
48
- 更早的 `kNoInput` 只说明「没有输入」,`kEmptyInput` 进一步说明是空输入;两者都在描述输入,而不是结果,最终改成 `kIgnored`。
49
-
50
- 注释也要跟着改名,但不要把「不为空」当状态:
51
-
52
- ```cpp
53
- ///< 失败:格子不为空 // 差
54
- ///< 失败:传入的是 kX 或 kO,格子已有值,没有写入 // 好
55
- ```
56
-
57
- `kOccupied` 要从传入的值起句:先写「传入的是 kX 或 kO」,再写「格子已有值」,末尾用「没有写入」说明这次调用没有改变格子;这比只写「格子不为空」既能核对原因,也交代了结果。`kIgnored` 写「传入的是 kEmpty,没有值可写」,`kSuccess` 写「传入的是 kX 或 kO,值已写入格子」,都不重复类型注释已经交代的失败后果。
@@ -1,104 +0,0 @@
1
- # 命名
2
-
3
- 命名先回答「它是什么角色」,再选词。规则表是底线,语义角色表决定用哪个动词。
4
-
5
- ## 规则表
6
-
7
- | 种类 | 规则 | 好 | 差 |
8
- | --- | --- | --- | --- |
9
- | 类型 / 类 / 结构 / 枚举 | PascalCase | `TaskTable`, `Order`, `TaskState` | `task_table_t`, `order_result` |
10
- | 函数 / 成员函数 | PascalCase | `Contains`, `GetTaskState` | `contains`, `gettaskstate` |
11
- | 变量 / 参数 | snake_case | `task_count`, `order` | `TaskCount`, `o` |
12
- | 类成员 | snake_case + `_` | `tasks_`, `orders_` | `m_tasks`, `tasks` |
13
- | 结构体成员 | snake_case,无尾随 `_` | `name`, `priority` | `name_`, `priority_` |
14
- | 常量 / 枚举子 | `k` + PascalCase | `kTaskCount`, `Order::kDraft` | `TASK_COUNT`, `Draft` |
15
- | 命名空间 | snake_case | `taskflow`, `warehouse` | `Taskflow`, `Warehouse` |
16
- | 宏 | 全大写 + 项目前缀,尽量不用 | `CPP_WORKFLOW_ASSERT` | `ASSERT` |
17
- | 模板类型参数 | PascalCase | `T`, `Item` | `t`, `item_t` |
18
- | 非类型模板参数 | 按常量或变量 | `kMaxItems`, `count` | `N`, `MAX` |
19
- | 概念 | PascalCase | `Sortable`, `Hashable` | `sortable`, `is_hashable` |
20
-
21
- - 文件名用 snake_case:`order_result.h`、`task_table.cpp`;测试文件 `task_table_test.cpp`。Google 也允许 `-`,本项目统一 `_`,与 target 和测试名保持一致。
22
- - 查询名与返回类型一致:返回格子取值时写 `GetCurrentValue`,返回玩家时写 `GetCurrentPlayer`;不写项目里没有对应类型的 `GetPlayer`。
23
- - 玩家互换用 `GetOpponent`,不写 `OtherPlayer`;玩家换成格子取值用 `PlayerToSquareValue`,不写 `SquareValueOf`。名字要点明两端角色。
24
- - 布尔变量用 `is_` / `has_` / `can_` 开头:`is_valid`、`has_stock`;不要用 `flag`、`status`。
25
- - 容器用复数:`tasks`、`orders`;单个元素用单数。
26
- - 缩写按单词处理:`url`、`id`、`http`,不要写 `URL` 混进 snake_case;类型名里可以 `HttpClient`。
27
- - 不用单字母名:坐标参数和局部变量用 `pos`(`position` 的常见缩写),行、列用 `row`、`col`;公开数据成员仍用完整名词(`Move::position`),避免 API 缩写。`i` / `j` 只用于没有领域名字的计数(如遍历固定长度的下标)。也不要用 `data`、`info`、`tmp` 这类不说明内容的名字。
28
- - 参数或局部变量的类型已在签名里写明时,用主流缩写而不是重复类型名:`Position pos`,不写 `Position position`;缩写只在含义无歧义时使用。
29
-
30
- ## 字符集与保留标识符
31
-
32
- - 代码标识符只用 ASCII:字母、数字、下划线。标准允许 Unicode XID 标识符,但工具链、字体与跨平台编辑不一致,Google 同样要求 ASCII。
33
- - 标识符大小写敏感;不要用只差大小写的两个名字区分不同实体。
34
- - 以下名字保留给实现,写了也不保证有诊断:任何位置出现双下划线 `__`;以下划线加大写字母开头;在全局命名空间中以下划线开头。
35
- - 不向 `std` 添加声明;只有在标准允许且依赖用户定义类型时,才特化标准模板(如 `std::formatter`、`std::hash`)。
36
- - 顶层命名空间取项目或团队独有的名字,避免与已有库冲突;不要嵌套 `std`、`absl` 这类知名顶层命名空间。
37
-
38
- ## 语义角色
39
-
40
- | 角色 | 前缀 / 动词 | 例子 | 说明 |
41
- | --- | --- | --- | --- |
42
- | 查询 | `Get` 或访问器风格 | `GetCurrentOrder()`、`CurrentOrder()` | 只读、不改变状态;同一 API 选一种 |
43
- | 判断 | `Is` / `Has` / `Can` | `IsEmpty()`、`HasStock()`、`HasLine()` | 返回 `bool`,不抛异常 |
44
- | 查找 | `Find` | `FindTask()` | 找不到是正常结果,返回 `optional` 或迭代器,不抛 |
45
- | 计数 | `Count` | `CountPendingTasks()` | 返回数量,不修改状态 |
46
- | 尝试 | `Try` / 领域动词 | `TryReserve()`、`Place()` | 可能因多个前置条件失败但不抛异常,返回 `enum class` 结果;调用方按名区分失败原因。只有一个失败原因、调用方不需要区分时返回 `bool` |
47
- | 确定性动作 | 领域动词 | `CompleteTask()`, `Reset()` | 前置条件满足时一定成功;无法完成任务时抛 |
48
- | 计算 | 动词开头 | `ScoreOrder()` | 从输入算出结果,不修改外部状态 |
49
- | 映射 | `<来源>To<目标>` | `OrderToReceipt()` | 名字必须含两端角色 |
50
- | 读写 | `Read` / `Write` | `ReadTaskTable()`, `WriteTaskTable()` | 涉及 I/O 时用;不要在库核心用 |
51
- | 访问器 | `Get` + PascalCase,或 snake_case | `GetHistory()`、`history()` | Google 允许两种;同一 API 只选一种,不用成员名直接当函数名 |
52
-
53
- - 返回 `bool` 的 lambda 也用 `is_` / `has_` / `can_` 命名:`auto is_empty = [](const Order& order) { ... };`。
54
- - `Find` 不把“没找到”当异常;`Get` 在前置条件不满足时抛标准异常:坐标越界用 `std::out_of_range`,调用时不变量已破坏用 `std::logic_error`;只有调用方必须把这些类型区分开时,才新增派生自它们的类型。两种构建模式的抛出条件相同。两者不要互换。
55
- - 查询返回多个值时用 `struct`,不要用三个 `GetXxx()` 加输出参数。
56
-
57
- - 禁止裸 `To()` / `Of()`:调用点看不出方向。
58
- - 修改器用 `Set` + 属性名(`SetCount()` / `set_count()`)或领域动作(`CompleteTask()`);同一 API 只选一种,不要用 `SetItem` 这类暴露存储细节的名字。
59
- - `current_` 前缀只在有多个候选、且「当前」可能混淆时使用:`current_order_`。只有一个当前对象时不要加。
60
-
61
- ## 谓词与查询命名
62
-
63
- - 返回 `bool` 的查询用肯定式,读起来像一句断言:`IsEmpty()`、`HasStock()`、`CanReserve()`、`HasLine()`。
64
- - 前缀集就是这四类:`Is` / `Has` / `Can`,外加与成对规则一一对应的 `Completes`、`Would` 这类限定式;`Contains` 只保留给容器成员(`std::vector::empty` 一类已有标准名),不拿它当一般谓词。
65
- - `Get` 只用于取值,`Set` 只用于设值;不要用 `CheckLine()` 当布尔 getter。
66
- - `Check` / `Validate` 留给会报告错误、产生诊断或可能失败的操作;它们不返回纯 `bool` 查询。
67
- - 动作可能因为多个前置条件失败、而调用方需要区分原因时,返回 `enum class`(`Square::PlaceResult`、`Game::PlaceResult`、`WinPreviewResult`),不要用 `bool` 加输出参数,也不要拆成一串 `IsXxx` 判断再重复检查。
68
- - 结果枚举的取值写结果类别,两个词以内:成功用 `kSuccess`;失败按发生原因分别取名(`kIgnored`、`kOccupied`、`kRejected`、`kDenied`),不合并成一个 `kInvalid`。行尾注释以类别开头,写成「成功:…」「失败:…」,冒号后写这次调用的结果与原因,各行按「传入的值 → 格子状态 → 写入结果」的顺序写。完整案例见 `references/naming/examples/naming-state-change.md`。
69
- - 结果枚举的类型用「操作或对象 + Result」,读作「什么的 Result」:`Place` 的结果是 `PlaceResult`,格子上一次写入的结果是 `Square::PlaceResult`。各层结果嵌在各自类型里,靠 `Square::PlaceResult` 与 `Game::PlaceResult` 区分,不要合成一个跨层的名字。
70
- - 枚举的取值写成短句,与类型名对齐:`BoardStatus` 用 `kInProgress`、`kXWon`、`kOWon`、`kDrawn`;`SquareValue` 用 `kEmpty`、`kX`、`kO`,行尾写「空格子」「X 标记」「O 标记」;不写 `kXWins` 这类主谓句,也不掺动作名。
71
- - 假设性查询在名字里写明条件:`PreviewWin(pos, cell)` 读作「这一次落子会成线吗」,返回 `WinPreviewResult` 区分「不能落子」与「能落但不赢」;只有成功与不报错的纯判断才用 `bool`。同一 API 只选一种,改名时同步声明、定义、调用点、测试和注释。
72
- - 私有谓词同样用肯定式;不要用 `flag`、`status` 或 `check` 这类不说明判据的名字。
73
-
74
- ## 类型命名的判断顺序
75
-
76
- 1. 纯数据、无 invariant、可以直接聚合初始化 → `struct`,名字是名词:`Order`, `TaskRecord`。
77
- 2. 有 invariant、需要构造函数维持 → `class`,名字是名词:`TaskTable`, `Warehouse`。
78
- 3. 封闭的状态集合 → `enum class`,名字是单数名词:`TaskState`, `OrderResult`;枚举子用 `k` 前缀。
79
- - 类型名用拥有它的那一层的词汇:`Board` 的返回值是 `BoardStatus`,不写 `GameResult`;`Game` 组合 `Board`,`Board` 不应出现 `Game` 前缀。反例见 `references/naming/examples/naming-lower-layer.md`。
80
- 4. 只有行为、没有状态,且调用方需要替换实现 → 抽象基类;只有一个实现时先用普通类。
81
- 5. 一组自由函数 → 命名空间 + 动词;不要为了「像 Java」造一个 `XxxUtil` 类。
82
-
83
- ## 改名
84
-
85
- - 改名是一次独立改动:先搜全部调用点,再改声明、定义、测试和注释。
86
- - 不要把改名和改行为混在一个提交里;改名后测试必须仍然绿色且行为句不变。
87
- - 公共 API 改名视为破坏性变更;需要兼容时保留旧名转发,并在注释里写弃用期限。
88
-
89
- ## 与 Google、Core Guidelines 的关系
90
-
91
- - 本工作流的命名基线是 Google C++ Style:类型与函数 PascalCase,变量 snake_case,常量与枚举子 `k` 前缀。项目内不再另立一套。
92
- - C++ Core Guidelines 的 NL 系列是“没有更好想法时的建议”。NL.10 偏好全 `underscore_style`,与本基线不同;这里采用它的 NL.5(名字不编码类型)、NL.7(名字长度与作用域成比例)、NL.8(风格一致)、NL.9(全大写只给宏)与 NL.19(避免易误读),不整体切换到 `underscore_style`。
93
- - 两者冲突时以本文件的明确规则为准;本文件没写的,按 Google 基线处理。
94
-
95
- ## 依据
96
-
97
- - ISO C++ `[lex.name]`:标识符字符集、大小写敏感与保留标识符。https://eel.is/c++draft/lex.name
98
- - ISO C++ `[namespace.std]`:向 `std` 添加声明与特化的限制。https://eel.is/c++draft/namespace.std
99
- - Google C++ Style Guide, Naming:https://google.github.io/styleguide/cppguide.html#Naming
100
- - C++ Core Guidelines, NL: Naming and layout:https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#s-naming
101
-
102
- ## 术语
103
-
104
- 中文术语与英文标识符的对应见 `references/language/glossary/language-terms.md`。代码标识符用英文;注释可以用中文,但同一个概念只用一种译法。
@@ -1,50 +0,0 @@
1
- # C++11 标准档案
2
-
3
- [返回标准索引](../README.md)
4
-
5
- | 项 | 值 |
6
- | --- | --- |
7
- | `standard` | `c++11` |
8
- | CMake meta-feature | `cxx_std_11` |
9
- | `CXX_STANDARD` | `11` |
10
- | `__cplusplus` | `201103L` |
11
- | clang-format 21/22 | `Standard: c++11` |
12
- | 模板实用下限 | GCC 4.8 / Clang 3.4 |
13
-
14
- ## 最重要的三件事
15
-
16
- 1. 代码只用 C++11 子集:没有 `std::make_unique`、通用 lambda、`std::string_view`、`std::optional`、`if constexpr`。
17
- 2. CMake 同时写 `cxx_std_11` 和 `CXX_STANDARD 11`,并开 `CXX_STANDARD_REQUIRED ON`;只写 `cxx_std_11` 可能被更高默认标准满足。
18
- 3. 验证时读 `compile_commands.json`,确认实际是 `-std=c++11`,不是 `gnu++11` 或更高的 `-std`。
19
-
20
- ## 本档能用
21
-
22
- - `auto`、范围 `for`、lambda、右值引用与移动语义。
23
- - `std::unique_ptr`、`std::shared_ptr`、`std::thread`、`std::chrono`。
24
- - `enum class`、`override` / `final`、变参模板、`constexpr` 的受限用法。
25
- - `std::array`、`std::unordered_map` / `unordered_set`。
26
-
27
- ## 本档不能假设
28
-
29
- - 没有 `std::make_unique`、泛型 lambda、变量模板、返回类型推导。
30
- - 没有 `std::string_view`、`std::optional`、`std::variant`、`if constexpr`、结构化绑定。
31
- - 没有 `[[nodiscard]]`、`std::filesystem`、`std::format`、`std::print`。
32
- - 不要用 C++14 的放宽 `constexpr` 写循环或多语句函数。
33
-
34
- ## CMake
35
-
36
- 把 [cmake-snippet.cmake](cmake-snippet.cmake) 的 target 名换成实际 target。新建工程仍建议 CMake ≥ 3.20;低版本工具链只影响 `CXX_STANDARD` 的可用性,不影响本工作流的目录约定。
37
-
38
- ## 工具
39
-
40
- - `.clang-format`:`Standard: c++11`。
41
- - `.clangd`:不写 `-std`,从 `compile_commands.json` 读。
42
- - `.clang-tidy`:仍用 Google 基线;不要打开 `cppcoreguidelines-*` 整包。
43
-
44
- ## 降档/升级
45
-
46
- 这是最低档,没有“再降”的路径。从 C++14 降到这里时,先去掉 `std::make_unique`、泛型 lambda、返回类型推导和变量模板;`std::unique_ptr<T>(new T(...))` 只作为过渡,不要在新代码里扩散。
47
-
48
- ## 验证
49
-
50
- configure、build、run 必测;`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++11`,不能是 `gnu++11`。模板的 `__cplusplus` 分支在 C++11 下应走字符串拼接实现。
@@ -1,48 +0,0 @@
1
- # C++14 标准档案
2
-
3
- [返回标准索引](../README.md)
4
-
5
- | 项 | 值 |
6
- | --- | --- |
7
- | `standard` | `c++14` |
8
- | CMake meta-feature | `cxx_std_14` |
9
- | `CXX_STANDARD` | `14` |
10
- | `__cplusplus` | `201402L` |
11
- | clang-format 21/22 | `Standard: c++14` |
12
- | 模板实用下限 | GCC 5 / Clang 3.4 |
13
-
14
- ## 最重要的三件事
15
-
16
- 1. C++14 只多出 `std::make_unique`、泛型 lambda、放宽的 `constexpr` 等;不要顺手用 C++17 的 `string_view`/`optional`。
17
- 2. `std::make_unique` 是这一档最常用的替换点,但不要把 C++11 的 `std::unique_ptr(new T)` 直接当成跨档写法。
18
- 3. 同样用 `CXX_STANDARD 14` + `REQUIRED ON` 锁定模式,并检查 `compile_commands.json` 是 `-std=c++14`。
19
-
20
- ## 本档能用
21
-
22
- - C++11 的全部内容。
23
- - `std::make_unique`、泛型 lambda、变量模板、返回类型推导。
24
- - 二进制字面量、数字分隔符、放宽的 `constexpr`、`std::integer_sequence`。
25
-
26
- ## 本档不能假设
27
-
28
- - 没有 `std::string_view`、`std::optional`、`std::variant`、`if constexpr`、结构化绑定。
29
- - 没有 `[[nodiscard]]`、`std::filesystem`、`std::format`、`std::print`。
30
- - 不要把结构化绑定或 `if constexpr` 写进 C++14 代码再靠编译器扩展通过。
31
-
32
- ## CMake
33
-
34
- 把 [cmake-snippet.cmake](cmake-snippet.cmake) 的 target 名换成实际 target。
35
-
36
- ## 工具
37
-
38
- - `.clang-format`:`Standard: c++14`。
39
- - `.clangd`:不写 `-std`,从 `compile_commands.json` 读。
40
- - `.clang-tidy`:仍用 Google 基线;命名规则不要引入 C++17 属性。
41
-
42
- ## 降档/升级
43
-
44
- 从 C++17 降到这里时,把 `string_view` 改成 `const std::string&`,把 `optional` 改成 `bool` + 输出参数或项目结果类型,把 `if constexpr` 改成标签分派或重载。升级到 C++17 后也不要立刻把公共接口全改成 `string_view`,先看调用方生命周期。
45
-
46
- ## 验证
47
-
48
- configure、build、run 必测;`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++14`。模板在 C++14 下应走字符串拼接实现。
@@ -1,50 +0,0 @@
1
- # C++17 标准档案
2
-
3
- [返回标准索引](../README.md)
4
-
5
- | 项 | 值 |
6
- | --- | --- |
7
- | `standard` | `c++17` |
8
- | CMake meta-feature | `cxx_std_17` |
9
- | `CXX_STANDARD` | `17` |
10
- | `__cplusplus` | `201703L` |
11
- | clang-format 21/22 | `Standard: c++17` |
12
- | 模板实用下限 | GCC 7 / Clang 5(语言核心) |
13
-
14
- ## 最重要的三件事
15
-
16
- 1. `std::string_view`/`std::optional`/`std::variant`/`if constexpr` 是这一档的主力;它们不能出现在 C++11/14 档案里。
17
- 2. 还没有 `std::format`;字符串拼接/`ostringstream` 仍是这一档的默认写法。
18
- 3. `std::filesystem` 在旧 GCC 上要额外链接 `stdc++fs`,先查工具链再写进 CMake。
19
-
20
- ## 本档能用
21
-
22
- - C++14 的全部内容。
23
- - `std::string_view`、`std::optional`、`std::variant`、`std::any`。
24
- - `if constexpr`、结构化绑定、`[[nodiscard]]`、内联变量、嵌套命名空间。
25
- - `std::filesystem`、并行算法(库实现和链接方式另看)。
26
-
27
- ## 本档不能假设
28
-
29
- - 没有 concepts、ranges、`std::format`、`std::span`、`std::bit_cast`。
30
- - 没有 `std::print`、`std::expected`、`std::stacktrace`。
31
- - 没有 `= default` 的比较运算符。
32
- - `std::filesystem` 在 GCC 8 需要额外链接 `stdc++fs`,GCC 9 起才稳定;不要把“语言核心达标”当成文件系统库也达标。
33
-
34
- ## CMake
35
-
36
- 把 [cmake-snippet.cmake](cmake-snippet.cmake) 的 target 名换成实际 target。用到 `std::filesystem` 且工具链较老时,在 target 上补 `stdc++fs`,不要全局加链接选项。
37
-
38
- ## 工具
39
-
40
- - `.clang-format`:`Standard: c++17`。
41
- - `.clangd`:不写 `-std`,从 `compile_commands.json` 读。
42
- - `.clang-tidy`:Google 基线;`[[nodiscard]]` 可以开始用于公共查询。
43
-
44
- ## 降档/升级
45
-
46
- 从 C++20 降到这里时,把 concepts 改成 `enable_if`/重载,把 ranges 改成迭代器算法,把 `std::format` 改成 `std::ostringstream`,把 `= default` 的比较运算符改回结构体外的手写自由函数。升级到 C++20 后先确认 `std::format` 的库门槛(libstdc++ 13+ / libc++ 14+),不要只看编译器版本。
47
-
48
- ## 验证
49
-
50
- configure、build、run 必测;`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++17`。模板在 C++17 下仍走字符串拼接实现。
@@ -1,50 +0,0 @@
1
- # C++20 标准档案
2
-
3
- [返回标准索引](../README.md)
4
-
5
- | 项 | 值 |
6
- | --- | --- |
7
- | `standard` | `c++20` |
8
- | CMake meta-feature | `cxx_std_20` |
9
- | `CXX_STANDARD` | `20` |
10
- | `__cplusplus` | `202002L` |
11
- | clang-format 21/22 | `Standard: c++20` |
12
- | 模板实用下限 | GCC 13 / Clang 16(`std::format`) |
13
-
14
- ## 最重要的三件事
15
-
16
- 1. `std::format` 是这一档的库门槛:libstdc++ 13+,libc++ 14+(特性宏到 19 才稳定),不是有 `-std=c++20` 就自动可用。
17
- 2. concepts/ranges/`std::span`/`std::bit_cast` 可以用;`std::print`、`std::expected`、`if consteval` 仍不能假设。
18
- 3. 模板在 `__cplusplus >= 202002L` 时切到 `std::format`;降回 C++17 时必须把它换回 `std::ostringstream`。
19
-
20
- ## 本档能用
21
-
22
- - C++17 的全部内容。
23
- - concepts、requires、ranges、`std::span`、`std::bit_cast`、`std::source_location`。
24
- - `std::format`、协程、`std::jthread`、三路比较。
25
- - 调用方需要按成员逐项比较时,写成 `bool operator==(const T&) const = default`。C++23 沿用,不另写一遍。
26
- - 模块语法(工具链支持不完整,模板不使用)。
27
-
28
- ## 本档不能假设
29
-
30
- - 没有 `std::print`、`std::expected`、`std::stacktrace`、`if consteval`、显式对象参数。
31
- - `std::format` 不只看语言核心:libstdc++ 13+;libc++ 14+ 实现完成,但特性宏到 19 才稳定。
32
- - 模块、协程的构建支持因编译器/构建系统而异;模板不依赖它们。
33
-
34
- ## CMake
35
-
36
- 把 [cmake-snippet.cmake](cmake-snippet.cmake) 的 target 名换成实际 target。模板从这一档开始会在 `__cplusplus >= 202002L` 时使用 `std::format`,此前用字符串拼接。
37
-
38
- ## 工具
39
-
40
- - `.clang-format`:`Standard: c++20`。
41
- - `.clangd`:不写 `-std`,从 `compile_commands.json` 读。
42
- - `.clang-tidy`:Google 基线;不要为了 concepts 打开一整族非 Google 检查。
43
-
44
- ## 降档/升级
45
-
46
- 从 C++23 降到这里时,把 `std::print` 改成 `std::format` + `std::cout`,把 `std::expected` 改成 `std::optional` 或项目结果类型,去掉 `if consteval`。升级到 C++23 后仍要逐项确认库实现,不要因为 `-std=c++23` 通过就假定 `print`/`stacktrace` 可用。
47
-
48
- ## 验证
49
-
50
- configure、build、run 必测;`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++20`。模板在 C++20 下应走 `std::format` 分支。
@@ -1,50 +0,0 @@
1
- # C++23 标准档案
2
-
3
- [返回标准索引](../README.md)
4
-
5
- | 项 | 值 |
6
- | --- | --- |
7
- | `standard` | `c++23` |
8
- | CMake meta-feature | `cxx_std_23` |
9
- | `CXX_STANDARD` | `23` |
10
- | `__cplusplus` | `202302L` |
11
- | clang-format 21/22 | `Standard: Latest` |
12
- | 模板实用下限 | GCC 13 / Clang 17(模板只用 `std::format`) |
13
-
14
- ## 最重要的三件事
15
-
16
- 1. C++23 在 GCC/Clang 上仍是 Partial;`std::print` 要 libstdc++ 14+/libc++ 19+,`std::stacktrace` 还要链接库。
17
- 2. clang-format 21/22 不认识 `c++23`,配置写 `Standard: Latest`;`.clangd` 不写 `-std`,否则会把编译数据库降回 C++20。
18
- 3. 模板默认 23,但模板只强依赖 `std::format`;不要因为默认 23 就在公共头里用 `std::expected`/`std::print`,先确认所有 target 和库门槛。
19
-
20
- ## 本档能用
21
-
22
- - C++20 的全部内容。
23
- - `std::print` / `std::println`、`std::expected`、`std::stacktrace`。
24
- - `if consteval`、显式对象参数(deducing this)、`std::mdspan`、`std::flat_map`。
25
- - ranges 的 C++23 增补(工具链实现为准)。
26
-
27
- ## 本档不能假设
28
-
29
- - C++23 在 GCC/Clang 上仍是 Partial:具体设施要查编译器状态页,不能只看 `-std=c++23`。
30
- - `std::print` 的库门槛是 libstdc++ 14+ / libc++ 19+;`std::stacktrace` 还要链接对应库,链接失败不是语法错误。
31
- - `std::expected` 的 monadic 接口、`std::flat_map` 等设施在旧标准库上可能缺失。
32
- - 模板只用 `std::format`,不会因为默认 C++23 就强依赖 `print`/`stacktrace`。
33
-
34
- ## CMake
35
-
36
- 把 [cmake-snippet.cmake](cmake-snippet.cmake) 的 target 名换成实际 target。默认模板的 `cxx_std_23` 和 `CXX_STANDARD 23` 必须与 `environment.json` 的 `standard` 一致。
37
-
38
- ## 工具
39
-
40
- - `.clang-format`:`Standard: Latest`(21/22 不接受 `c++23`;`Latest` 按工具支持的最高标准解析)。
41
- - `.clangd`:不写 `-std`,从 `compile_commands.json` 读;写死 `-std=c++20` 会让 `<print>` 和 `if consteval` 解析失败。
42
- - `.clang-tidy`:Google 基线;不要因为 C++23 就打开 `cppcoreguidelines-*` 整包。
43
-
44
- ## 降档/升级
45
-
46
- 从 C++23 降到 C++20 见 [C++20 档案](../c++20/README.md)。升级到 C++26 前先确认 CMake 3.25+、编译器/标准库支持、clang-format 的 `c++26` 枚举;新增目录流程见 [标准索引](../README.md#新增标准)。
47
-
48
- ## 验证
49
-
50
- configure、build、run 必测;`compile_commands.json` 的最后一个 `-std=` 必须是 `-std=c++23`。模板在 C++23 下走 `std::format` 分支;若使用 `print`/`stacktrace`,另做链接测试。
@@ -1,22 +0,0 @@
1
- # 正反例:GLOB
2
-
3
- **差**:
4
-
5
- ```cmake
6
- file(GLOB SOURCES "src/*.cpp")
7
- add_executable(app ${SOURCES})
8
- ```
9
-
10
- 新增文件不触发重新配置;不同机器上的文件集合可能不同。
11
-
12
- **好**:
13
-
14
- ```cmake
15
- add_executable(app
16
- src/main.cpp
17
- src/task_list.cpp
18
- src/task_parser.cpp
19
- )
20
- ```
21
-
22
- 显式列表,新增文件时改 CMake;diff 能看出变化。