@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,23 +0,0 @@
|
|
|
1
|
-
# 命名术语与用词
|
|
2
|
-
|
|
3
|
-
本文件是 `references/naming/identifier-names.md` 的附录,只在判不准某个词该用完整写法还是缩写时打开;它不随该文件一起加载,也不重复命名规则表。
|
|
4
|
-
|
|
5
|
-
一词一文件只用于命名主题的词汇;注释与语言主题仍用单份术语文件,不按这个结构拆。
|
|
6
|
-
|
|
7
|
-
## 词表
|
|
8
|
-
|
|
9
|
-
| 词 | 结论 | 条目 |
|
|
10
|
-
| --- | --- | --- |
|
|
11
|
-
| `position` / `pos` | 坐标值的参数与局部变量用 `pos`;公开数据成员用 `position`;迭代器式位置对象用 `position` | [position.md](position.md) |
|
|
12
|
-
| `square` / `SquareValue` | 方格;方格的值;不用 `Mark`、`Cell`、`Token` | [square.md](square.md) |
|
|
13
|
-
|
|
14
|
-
## 加词流程
|
|
15
|
-
|
|
16
|
-
1. 查 ISO C++ 草案对应条款,记下标准自己的写法。
|
|
17
|
-
2. 查一个标准库实现(libstdc++ 或 libc++)与一个同类库(Qt、SFML、Godot)。
|
|
18
|
-
3. 结论写进 `glossary/<词>.md`,词表加一行链接;只有一词多义或社区争议大时,才在词条里展开。
|
|
19
|
-
4. 同一事实只写一遍:规则在 `identifier-names.md`,依据与取舍在词条里。
|
|
20
|
-
|
|
21
|
-
## 词条格式
|
|
22
|
-
|
|
23
|
-
每个词条按 [position.md](position.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 | `Standard: Latest`(23 起可写 `c++23`) |
|
|
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`,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`,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 能看出变化。
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
# 正反例:target 与输出目录
|
|
2
|
-
|
|
3
|
-
## 最小可用形状
|
|
4
|
-
|
|
5
|
-
```cmake
|
|
6
|
-
cmake_minimum_required(VERSION 3.20)
|
|
7
|
-
project(greeter VERSION 0.1.0 LANGUAGES CXX)
|
|
8
|
-
|
|
9
|
-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
10
|
-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
11
|
-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
12
|
-
|
|
13
|
-
# 先把 assets/ 里的 CompileSettings.cmake 复制到工程的 cmake/。
|
|
14
|
-
include(CompileSettings)
|
|
15
|
-
|
|
16
|
-
add_library(greeting STATIC greeting/src/greeting.cpp)
|
|
17
|
-
target_include_directories(greeting PUBLIC greeting/include)
|
|
18
|
-
CompileSettings_SetCxxStandard(greeting PUBLIC c++23)
|
|
19
|
-
CompileSettings_SetWarnings(greeting PRIVATE LEVEL standard)
|
|
20
|
-
|
|
21
|
-
add_executable(app src/main.cpp)
|
|
22
|
-
CompileSettings_SetCxxStandard(app PRIVATE c++23)
|
|
23
|
-
CompileSettings_SetWarnings(app PRIVATE LEVEL standard)
|
|
24
|
-
target_link_libraries(app PRIVATE greeting)
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
程序只写 `#include "greeting.h"`;公共 include 根由库的 `PUBLIC` 传过来。
|
|
28
|
-
|
|
29
|
-
## 全局 include
|
|
30
|
-
|
|
31
|
-
**差**:
|
|
32
|
-
|
|
33
|
-
```cmake
|
|
34
|
-
include_directories(include greeting/include)
|
|
35
|
-
add_executable(app src/main.cpp greeting/src/greeting.cpp)
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
问题:所有 target 共享 include,边界消失;程序直接编译库源码,测试无法只链接库。
|
|
39
|
-
|
|
40
|
-
**好**:
|
|
41
|
-
|
|
42
|
-
```cmake
|
|
43
|
-
target_include_directories(greeting PUBLIC greeting/include)
|
|
44
|
-
target_link_libraries(app PRIVATE greeting)
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## 把 `main()` 编进库
|
|
48
|
-
|
|
49
|
-
**差**:
|
|
50
|
-
|
|
51
|
-
```cmake
|
|
52
|
-
add_library(core STATIC src/main.cpp src/core.cpp)
|
|
53
|
-
add_executable(app src/main.cpp) # 重复定义
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**好**:
|
|
57
|
-
|
|
58
|
-
```cmake
|
|
59
|
-
add_library(core STATIC src/core.cpp)
|
|
60
|
-
add_executable(app src/main.cpp)
|
|
61
|
-
target_link_libraries(app PRIVATE core)
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
库不依赖 `main()`;测试链接库时不会碰到入口。
|
|
65
|
-
|
|
66
|
-
## 警告等级
|
|
67
|
-
|
|
68
|
-
**差**:
|
|
69
|
-
|
|
70
|
-
```cmake
|
|
71
|
-
target_compile_options(app PRIVATE -Wall -Wextra -Werror)
|
|
72
|
-
target_compile_options(core PRIVATE -Wall -Wextra -Werror)
|
|
73
|
-
# 每个 target 复制一遍;想加 -Wshadow 时要逐处改
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**好**:
|
|
77
|
-
|
|
78
|
-
```cmake
|
|
79
|
-
CompileSettings_SetWarnings(app PRIVATE LEVEL standard)
|
|
80
|
-
CompileSettings_SetWarnings(core PRIVATE LEVEL strict)
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
`basic` 只开 `-Wall -Wextra`;`standard` 加 `-Werror`、`-Wshadow`、`-Wold-style-cast`、`-Wpedantic`、`-Wnon-virtual-dtor`、`-Woverloaded-virtual`;`strict` 再加转换、格式化与可移植性告警。警告只作用于传入 target,不通过 `INTERFACE` 传播。
|
|
84
|
-
|
|
85
|
-
## 编译数据库
|
|
86
|
-
|
|
87
|
-
**差**:
|
|
88
|
-
|
|
89
|
-
```cmake
|
|
90
|
-
# 没开导出
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
clang-tidy src/main.cpp # 没有编译参数,头路径和标准都不对
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
**好**:
|
|
98
|
-
|
|
99
|
-
```cmake
|
|
100
|
-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
cmake -S . -B build/clang -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
|
|
105
|
-
rm -f build/compile_commands.json
|
|
106
|
-
ln -s clang/compile_commands.json build/compile_commands.json
|
|
107
|
-
clang-tidy -p build/clang src/main.cpp
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## 输出目录
|
|
111
|
-
|
|
112
|
-
**差**:可执行文件生成在源码根,`git status` 出现 `app`、`*.o`。
|
|
113
|
-
|
|
114
|
-
**好**:
|
|
115
|
-
|
|
116
|
-
```cmake
|
|
117
|
-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
118
|
-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
119
|
-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
构建产物全在 `build/<compiler>/` 下。
|
|
123
|
-
|
|
124
|
-
## 注释
|
|
125
|
-
|
|
126
|
-
**差**:
|
|
127
|
-
|
|
128
|
-
```cmake
|
|
129
|
-
#[[.rst:
|
|
130
|
-
CompileSettings_SetWarnings
|
|
131
|
-
---------------------------
|
|
132
|
-
|
|
133
|
-
.. command:: CompileSettings_SetWarnings(target visibility)
|
|
134
|
-
|
|
135
|
-
:param target: 目标。
|
|
136
|
-
@param visibility: 可见性。
|
|
137
|
-
@return: 无。
|
|
138
|
-
]]
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
`#[[.rst:` 与 `.. command::` 是给要进 CMake 手册的模块用的抽取标记,本仓模块不进手册;`@param`、`@return` 是 C++ 的 Doxygen 标签,CMake 里不用。CMake 函数也没有返回值,`:return:` 同样不写。
|
|
142
|
-
|
|
143
|
-
**好**:
|
|
144
|
-
|
|
145
|
-
```cmake
|
|
146
|
-
# 给一个目标加上编译警告。
|
|
147
|
-
#
|
|
148
|
-
# 只改传入的目标。PRIVATE 不向使用方传播。
|
|
149
|
-
#
|
|
150
|
-
# :param target: 已经存在的 CMake 目标。
|
|
151
|
-
# :param visibility: 取 PRIVATE 或 INTERFACE。
|
|
152
|
-
# :keyword LEVEL: 可省略。取 basic、standard 或 strict;省略时按 standard。
|
|
153
|
-
function(CompileSettings_SetWarnings target visibility)
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
普通 `#` 行,签名留在 `function()` 那一行;位置参数用 `:param`,`cmake_parse_arguments` 的关键字用 `:keyword`。
|
|
File without changes
|