Skip to content

docs(cpp14): add 01-relaxed-constexpr book chapter, exercises, solutions, and build wiring#75

Open
lczllx wants to merge 2 commits into
mcpp-community:mainfrom
lczllx:feat/cpp14-01-relaxed-constexpr
Open

docs(cpp14): add 01-relaxed-constexpr book chapter, exercises, solutions, and build wiring#75
lczllx wants to merge 2 commits into
mcpp-community:mainfrom
lczllx:feat/cpp14-01-relaxed-constexpr

Conversation

@lczllx

@lczllx lczllx commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

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):

  • section 一/I: Basic usage — for/while loops, if/switch branches,
    local variables, multiple statements, compile-time Fibonacci
  • section 二/II: Real-world case — std::make_index_sequence and
    std::tuple compile-time construction, cited from vendored
    msvc-stl/stl/inc/tuple and msvc-stl/stl/inc/utility
  • section 三/III: Notes — still-banned operations (goto, try/catch,
    static locals, asm, uninitialized vars), dual nature of constexpr,
    ODR linkage note (implicit inline is C++17, not C++14)
  • section 四/IV: Exercise topics and d2x checker command
  • section 五/V: External resources

Exercise progression:
0. constexpr with loops — compile-time factorial (for) and power
(while). Learner fills loop condition and return expressions.
4 D2X_YOUR_ANSWER.

  1. constexpr with branches and local variables — if-branch my_abs,
    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.

@lczllx lczllx force-pushed the feat/cpp14-01-relaxed-constexpr branch from f670d61 to 9004bbe Compare June 20, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SubTask: C++14 - 01 - relaxed constexpr

1 participant