constexpr: Applications
summary
Shows how to implement a constexpr binary literal in C++11 via recursive constexpr parsing and static_asserts, and how C++14 replaces recursion with a cleaner nonrecursive version. Demonstrates compile-time tables: a generated sine table, a compile-time insertion sort plus static validation, a sorted-array associative lookup using equal_range, and a tiny perfect hash for four strings. Notes limits (recommended recursion depth ~512, >1,000,000 full-expressions), clang/GCC C++14 support, Visual Studio gaps, and a unresolved extern hack that forces compile-time evaluation for constexpr containers but is compiler/linker dependent.
AI-written summary · about
chapters (28)
- 0:00Intro
- 2:08constexpr Contexts
- 2:41constexpr Values
- 3:30constexpr Computations
- 7:28Using constexpr11_bin
- 8:40constexpr 14 bin
- 9:27constexpr Limits
- 11:29User Errors at Compile Time
- 15:23User Errors At Runtime
- 15:44Runtime Execution?
- 18:19Guidance
- 22:45Technique Summary
- 23:06Compile-Time Parsing Summary
- 24:26Motivation
- 26:29First constexpr Array
- 28:11Returning a constexpr Array
- 33:22Non-const constexpr Methods
- 34:50generate sine
- 38:01Try generate_sine
- 41:54Test constexpr_to_upper
- 44:56Test constexpr_is_alphabetical
- 50:36Test constexpr_str_sort
- 51:51Compile-Time Associative Containers
- 53:14constexpr Unordered Containers?
- 56:18Perfect Minimal Hash Function
- 56:54constexpr Container Downsides
- 57:42constexpr Container Summary
- 58:33Topics
related talks
01h 10m“constexpr ALL the Things!”
01h 03mOLD VERSION: Understanding The constexpr 2-Step
01h 03mUnderstanding The constexpr 2-Step
01h 04m“Constant Fun"
01h 09m“Compile-time programming and reflection in C++20 and beyond”
01h 00mRemoving Metaprogramming From C++, Part 1 of N: constexpr Function Params
01h 02mImplementing `static` control flow in C++14
01h 03mCompile-Time Regular Expressions
