Skip to content

book: add idiomatic std::tuple traversal#313

Merged
changkun merged 1 commit into
masterfrom
fix/294-tuple-traversal
Jun 7, 2026
Merged

book: add idiomatic std::tuple traversal#313
changkun merged 1 commit into
masterfrom
fix/294-tuple-traversal

Conversation

@changkun
Copy link
Copy Markdown
Owner

@changkun changkun commented Jun 7, 2026

The existing tuple traversal builds on the variant-based runtime indexing plus a for loop, which is roundabout. Add the idiomatic compile-time approaches: C++17 fold + std::index_sequence, and the C++20 templated-lambda form. Both verified to compile and output 1 1.2 str.

Fixes #294

The existing tuple traversal builds on the variant-based runtime indexing
and a for loop, which is roundabout for simply applying an operation to
each element. Add the idiomatic compile-time approaches: C++17 fold +
std::index_sequence, and the C++20 templated-lambda form. Both verified
to compile and produce correct output.

Fixes #294
@changkun changkun merged commit d353740 into master Jun 7, 2026
@changkun changkun deleted the fix/294-tuple-traversal branch June 7, 2026 14:32
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.

第四章 std::tuple 的遍历的内容有些过时与复杂

1 participant