docs(cpp): 补全 inline constexpr 练习答案 - #206
Merged
Charliechen114514 merged 1 commit intoSep 3, 2026
Merged
Conversation
Member
|
摸个🐟,看起来没啥问题,approve了 |
Charliechen114514
merged commit Sep 3, 2026
2523f31
into
Awesome-Embedded-Learning-Studio:main
5 checks passed
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.
修复说明
本 PR 完善
inline与constexpr教程中的三道练习参考答案,并统一示例代码格式。此前练习部分只有题目,缺少可运行的参考实现;同时已有示例存在缩进、命名、命令空格和函数签名不一致等问题,容易影响读者理解和复制运行。
修复类型
具体改动
涉及文件:
documents/vol1-fundamentals/ch03/04-inline-constexpr.md练习一:constexpr 最大公约数
constexpr gcd实现。static_assert,验证:gcd(12, 8) == 4gcd(100, 75) == 25练习二:编译期斐波那契查找表
constexpr fibonacci()函数。std::array<std::uint32_t, 30>查找表。static_assert,验证:table[10] == 55table[20] == 6765snake_case风格。fib.size()和table.size()控制循环边界。练习三:constexpr popcount
constexpr int count_bits(int n)。unsigned int执行 Brian Kernighan 位计数算法,避免对负数执行有符号溢出操作。static_assert,验证:count_bits(0) == 0count_bits(7) == 3count_bits(255) == 8其他格式调整
<<运算符空格。&&两侧空格。reading_time_minutes从12更新为19。影响范围
仅影响上述教程文章,不涉及:
本篇文章原有位置和链接无需调整。
验证方式
已完成以下检查:
g++ -std=c++17 -Wall -Wextra -pedantic编译通过。0。markdownlint检查通过。scripts/check_quality.py documents/vol1-fundamentals/ch03检查通过。scripts/validate_frontmatter.py检查通过,991 个 Markdown 文件全部有效。git diff --check检查通过。关联 Issue / Discussion
暂无。