Skip to content

feat(cpp14): add 02-variable-templates book chapter, exercises, solutions, and build wiring#76

Open
lczllx wants to merge 1 commit into
mcpp-community:mainfrom
lczllx:feat/cpp14-02-variable-templates
Open

feat(cpp14): add 02-variable-templates book chapter, exercises, solutions, and build wiring#76
lczllx wants to merge 1 commit into
mcpp-community:mainfrom
lczllx:feat/cpp14-02-variable-templates

Conversation

@lczllx

@lczllx lczllx commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

feat(cpp14): add 02-variable-templates book chapter, exercises, solutions, and build wiring

Add the third C++14 chapter covering variable templates.

Book chapter (zh + en):

  • section 一/I: Basic usage — pi constant, _v traits, compile-time
    config values, recursive variable template
  • section 二/II: Real-world case — _Is_iterator_v from vendored
    msvc-stl/stl/inc/xutility, demonstrating variable template with
    partial specialization replacing ::value pattern
  • section 三/III: Notes — full and partial specialization support
  • section 四/IV: Exercise topics and d2x checker command
  • section 五/V: External resources

Exercise progression:
0. Basic variable template — pi constant and compile-time buffer
config with explicit specialization. 4 D2X_YOUR_ANSWER.

  1. _v type traits — implementing is_void_v, is_same_v, and
    recursive factorial_v. 5 D2X_YOUR_ANSWER.

STL case notes:
The vendored _Is_iterator_v was chosen because it (1) is a real
variable template used internally by the MSVC STL, (2) demonstrates
partial specialization of a variable template, and (3) directly
illustrates the motivation — eliminating ::value boilerplate from
type traits. This predates and motivates the C++17 standardized _v
traits like is_same_v.

Build wiring:

  • register 02 targets in dslings/cpp14, dslings/en/cpp14,
    solutions/cpp14
  • add 02 entry to zh/en SUMMARY.md

Closes #62

CLA: I have read the CLA and by submitting this PR agree to its terms.

Book chapter (zh + en):
  - section 一/I: Basic usage — pi constant, _v traits, compile-time
    config values, recursive variable template
  - section 二/II: Real-world case — _Is_iterator_v from vendored
    msvc-stl/stl/inc/xutility, demonstrating variable template with
    partial specialization replacing ::value pattern
  - section 三/III: Notes — full and partial specialization support
  - section 四/IV: Exercise topics and d2x checker command
  - section 五/V: External resources

Exercise progression:
  0. Basic variable template — pi constant and compile-time buffer
     config with explicit specialization. 4 D2X_YOUR_ANSWER.
  1. _v type traits — implementing is_void_v, is_same_v, and
     recursive factorial_v. 5 D2X_YOUR_ANSWER.

STL case notes:
  The vendored _Is_iterator_v was chosen because it (1) is a real
  variable template used internally by the MSVC STL, (2) demonstrates
  partial specialization of a variable template, and (3) directly
  illustrates the motivation — eliminating ::value boilerplate from
  type traits. This predates and motivates the C++17 standardized _v
  traits like is_same_v.

Build wiring:
  - register 02 targets in dslings/cpp14, dslings/en/cpp14,
    solutions/cpp14
  - add 02 entry to zh/en SUMMARY.md
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 - 02 - variable templates

1 participant