Cute C++ Tricks, Part 2.5 of N - Code You Should Learn From & Never Write
summary
Dissects 25-line C++ snippets that teach and tempt: shows the actual hacks, why they work, and when they fail. Demonstrates partial specialization via lambda requires using explicit template parameters and Godbolt experiments, points out a Clang implementation bug, and contrasts an implementation using class-template partial specialization with a typeless sort sketch that builds a variant array and sorts type indices. Also shows a literal-indexed tuple built from a user-defined literal template. Most tricks work but are unsafe for production.
AI-written summary · about
chapters (29)
- 0:00Intro
- 1:10Goals
- 2:43Confession
- 5:42Disclaimers
- 7:40Concepts
- 9:13Edible
- 10:52Partial Specialization
- 13:36Shadowing
- 14:59Named Concepts
- 17:13Specialization
- 18:36Subsumption Specific
- 20:13Name Concepts
- 21:11Function Template Partial Specialization
- 24:29Challenges
- 29:27Challenge 1B
- 30:51Challenge 2A
- 34:02General Pattern
- 34:45Overloads
- 35:14Why you should never write this
- 36:34Better ways to do this
- 38:03More tricks
- 39:11C literals
- 41:19Userdefined literals
- 42:37Userdefined literal templates
- 44:56Userdefined literal suffix
- 45:40Resolving at compile time
- 46:27Questions
- 50:01Nonevaluating Context
- 54:31Class Template TMP
related talks
01h 11mC++20 Templates: The next level: Concepts and more
01h 03mTemplate-less Metaprogramming in C++
01h 03mTemplates Made Easy with C++20
49mTypical C++, But Why?
01h 03mTemplate Metaprogramming: Practical Application
07mLightning Talk: Higher-Order Template Metaprogramming with C++23
01h 05mBack to Basics: Lambdas
01h 10mType Deduction and Why You Care
