docs(cpp14): add 00-generic-lambdas book chapter, exercises, solutions, and build wiring
docs(cpp14): add 00-generic-lambdas book chapter, exercises, solutions, and build wiring
Add the first C++14 chapter covering generic lambdas.
Book chapter (zh + en):
- section 一/I: Basic usage — identity, multi-param, STL algorithms, captures, returning lambda (factory pattern)
- section 二/II: Notes — closure type uniqueness, perfect forwarding, non-variadic
- section 三/III: Exercise topics and d2x checker command
- section 四/IV: External resources
- register chapter in zh/en SUMMARY.md and book/README.md
Exercise progression: 0. Basic generic lambda — auto parameter identity/comparison/type-size exercises. Learner fills auto param type, return expression, and sizeof argument. 4 D2X_YOUR_ANSWER.
- Generic lambda with STL algorithms — same lambda reused across
vector
and vector for sort/find_if, plus a factory pattern returning a lambda. 5 D2X_YOUR_ANSWER.
Design rationale: Generic lambdas have three layers worth teaching independently: (1) syntax — auto in lambda parameters generates a templated operator(); (2) reuse — a single lambda serves multiple container types, the primary motivation for the feature; (3) interaction — generic lambda returns + captures work naturally without extra syntax.
ex 0 isolates layer (1). identity forces the learner to write auto in a parameter position. greater verifies the return expression is type-checked per instantiation. get_type_size confirms that sizeof on a generic parameter works correctly, reinforcing the "compiler stamps out per-type copies" mental model.
ex 1 layers (2) and (3) on top. The desc lambda applied to both
vector
We deliberately limited this chapter to 2 exercises. A third exercise covering perfect forwarding + auto&& + decltype(auto) is better placed in the decltype(auto) chapter where the forwarding semantics are the primary topic, not a side note.
Build wiring:
- register cpp14 in dslings/xmake.lua, dslings/en/xmake.lua, solutions/xmake.lua
- new xmake.lua per directory with set_languages("cxx14")
- remove stale dslings/cpp14/README.md TODO placeholder
Closes #60
CLA: I have read the CLA and by submitting this PR agree to its terms.