Nth Pack Element in C++ - A Case Study
summary
Compares concrete implementations for grabbing the nth element of a variadic pack, builds and runs benchmarks with metabench and Compiler Explorer, and measures compilation times across GCC, Clang, Circle and languages like Rust, Nim and D. Finds recursion is slow, library solutions like mp11 performs well, Clang’s type_element intrinsic and preprocessor tricks help, and Circle (and the proposed language feature) flattens compile time — benchmarks show huge, surprising gaps and practical tradeoffs.
AI-written summary · about
chapters (28)
- 0:00Introduction and goals
- 1:55Motivation and use cases
- 2:39Current state and limitations
- 4:46First and last elements
- 6:30Structured bindings proposal
- 7:45The Nth element challenge
- 9:45Overview of solutions
- 11:11List of technical approaches
- 13:05Using std::array
- 15:16Recursion techniques
- 17:29Immediate invocations
- 19:27Dark magic approaches
- 22:31Using Boost.MP11
- 25:15Preprocessor solution
- 28:51Inheritance-based approach
- 30:53Compiler intrinsics
- 32:28The Circle compiler
- 34:07Future proposals
- 35:49Tuple implementation details
- 37:30Lambda-based tuples
- 39:23Integral constants in tuples
- 42:11Compile-time ranges
- 44:12Benchmarking methodology
- 46:18Benchmark results: GCC and Clang
- 49:48Benchmark results: Circle
- 51:46Tuple benchmarking analysis
- 53:36Language comparison
- 55:13Conclusion and future outlook
related talks
01h 03mTemplate-less Metaprogramming in C++
01h 02mDiscovering a User-Facing Concept
01h 04mC++ Concepts
06mLightning Talk: Unlocking More Ways To Use Range-Based For
01h 03mTemplate Metaprogramming: Practical Application
58mExpressive Compile-time Parsers in C++
07mLightning Talk: Higher-Order Template Metaprogramming with C++23
05mLightning Talk: The Main Points in C++ - Dots in C++
