docs(cpp): 补全std::array答案 - #216
Open
xiaoshuaijie wants to merge 1 commit into
Open
Conversation
Charliechen114514
left a comment
Member
There was a problem hiding this comment.
先看看下面的评论,如果不是的话,还是改一下比较好,有点忘记了
| std::cout << x << " "; | ||
| } | ||
| std::cout << "\n"; | ||
| auto [min_it, max_it] = std::minmax_element(arr.begin(), arr.end()); |
Member
There was a problem hiding this comment.
unpack解包功能咱们前面的文章有提到吗?会不会超纲了?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复说明
延续"补全练习参考答案"系列(#207、#208、#211、#214 等),为 vol1-fundamentals ch05 的《std::array》一文补全练习部分的参考答案:
::: details 参考答案折叠块,内含完整示例代码、编译运行命令与实测运行结果。示例覆盖std::array的声明与初始化、range-for 遍历、static_cast<double>计算平均分;统计操作全部使用<algorithm>(std::sort排序,std::minmax_element一次取最小/最大值,并用 C++17 结构化绑定接收结果)。contains按const std::array<int, 5>&传参(呼应本章"传参"小节),内部用std::find与end()比较判断;main中分别测试存在(43)与不存在(99)两种情况。std::array重写),标注"自行练习就好",不提供固定答案。reading_time_minutes由10调整为11,反映新增内容。答案块格式(代码 → 编译运行 → 运行结果)与已合并的同类 PR 保持一致。
修复类型
影响范围
documents/vol1-fundamentals/ch05/02-std-array.md(1 file changed,+95 / −1)reading_time_minutes;title/chapter/order/tags均未变,无需更新导航或索引。验证方式
本地环境:WSL2 Ubuntu 24.04,g++ 13.3.0(Ubuntu 13.3.0-6ubuntu2~24.04.1)。
如包含代码,已说明是否测试过:两段参考答案代码均提取到
/tmp,以g++ -std=c++17 -Wall -Wextra编译,零警告,实际输出与文中"运行结果"逐字一致:练习二:
练习三:
frontmatter 校验:
.venvPython 运行scripts/validate_frontmatter.py,全仓 991 个文件通过(0 warnings / 0 errors)。Markdown 可以正常阅读:结构沿用文中既有
::: details折叠与代码块写法(与 docs(cpp): 补全指针基础练习答案 #207 等已合并 PR 一致);markdownlint 本地未安装,由 CI 复查。如修改正式教程文章,已考虑是否需要更新导航或索引:无需,frontmatter 结构未变。
注:本分支基于
037f34f(#207);上游 main 之后新增的提交(#208–#215)与本 PR 无文件重叠,合并不存在冲突风险。关联 Issue / Discussion
无关联 issue;