TMI on UDLs: Mechanics, Uses, and Abuses of User-Defined Literals
summary
Explains all six UDL kinds, shows cooked literals versus raw literal operator parsing, and demonstrates a literal operator template that gets the character pack so dates can be syntactically validated at compile time, long numeric literals (128/256-bit) can be parsed reliably, and octal/binary surprises avoided. Covers integer/float/char/string signatures, currency literals using long double, namespace-hiding of UDLs in the std style, and enable_if/trailing-return overloads to pick behaviors; examples compile and run as constant expressions.
AI-written summary · about
chapters (14)
- 0:00Introduction to UDLs
- 1:54Solving date type problems
- 3:40Why use user-defined literals
- 5:51Gotchas with UDL arguments
- 7:14Representing money safely
- 10:45Cooked vs raw literal operators
- 13:55Custom suffixes for clarity
- 15:21Date literals and pitfalls
- 17:12Raw literal operator templates
- 22:36Literal operator template benefits
- 24:44Why prefer template operators
- 27:53Google’s UDL concerns
- 29:38Conditional UDL compilation
- 31:25Summary and Q&A
related talks
01h 31mImplementing Physical Units Library for C++
48mCross-Domain Compilation: Exploiting Synergies Across the CS Community
01h 30mRethinking the Way We Do Templates in C++
01h 01mExpressive Compile Time Parsers
45mC++ is a Metacompiler
54mUndefined Behaviour is awesome!
01h 04mconstexpr: Introduction
01h 34mMetaprogramming in C++14
