docs(cpp14): add 01-relaxed-constexpr book chapter, exercises, solutions, and build wiring#75
Open
lczllx wants to merge 2 commits into
Open
Conversation
f670d61 to
9004bbe
Compare
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.
docs(cpp14): add 01-relaxed-constexpr book chapter, exercises, solutions, and build wiring
Add the second C++14 chapter covering relaxed constexpr.
Book chapter (zh + en):
local variables, multiple statements, compile-time Fibonacci
std::tuple compile-time construction, cited from vendored
msvc-stl/stl/inc/tuple and msvc-stl/stl/inc/utility
static locals, asm, uninitialized vars), dual nature of constexpr,
ODR linkage note (implicit inline is C++17, not C++14)
Exercise progression:
0. constexpr with loops — compile-time factorial (for) and power
(while). Learner fills loop condition and return expressions.
4 D2X_YOUR_ANSWER.
switch-branch days_in_month, multi-variable Fibonacci. Learner
fills branch conditions, switch default, initial values and
return expressions. 6 D2X_YOUR_ANSWER.
Design rationale:
The jump from C++11 single-return constexpr to C++14 loop/branch
constexpr is the single most impactful constexpr change. ex 0
isolates loop relaxation — factorial uses for, power uses while,
both forms C++11 forbade. ex 1 layers on branching and multiple
local variables, showing that C++14 constexpr functions can look
like normal functions.
The STL case uses std::make_index_sequence + std::tuple because
index_sequence was introduced in C++14 alongside relaxed constexpr
and is the prime example of compile-time integer generation enabling
pack expansion — a pattern unavailable in C++11.
Closes #61
CLA: I have read the CLA and by submitting this PR agree to its terms.