~/talk

Embracing User Defined Literals Safely for Types that Behave as though Built-in

Talkat CppCon 2021 · on Tuesday, 2021-10-26· at 09:00· online· [javascript]
slides:none on file

Shows exactly how to write and choose among cooked, raw, template and string UDLs, using real code: a base‑3 numeric parser turned into a compile‑time operator""_3 template with overflow checks via static_assert, an IP v4/v6 detector that selects return type, a compile‑time fixed‑point constructor, and chrono/unit examples. Covers practical tools—consteval vs constexpr, non‑type char template packs, namespace literal idiom—and failures like implicit octal confusion and negation-before‑UDL producing below‑zero temperatures. C++17 recipes and C++20 improvements are contrasted; implementations and pitfalls are shown, not just theory.

AI-written summary · about

  1. 0:00Start
  2. 1:10literal in C++
  3. 3:48About me
  4. 4:22Coming soon to a bookstore near you!
  5. 5:21What is a user-defined literal (UDL)?
  6. 7:20Anatomy of a UDL
  7. 8:55Restrictions on UDLS
  8. 12:10So, aren't UDLs just syntactic sugar?
  9. 12:57The UDL operator
  10. 13:40Namespaces for literals
  11. 14:54Cooked UDL operators
  12. 17:46Cooked UDL examples
  13. 23:13Raw UDL operator example: Base 3 int
  14. 25:41Base 3 int with error detection
  15. 28:00Force compile-time error detection
  16. 28:49Raw UDL operators: Nota Bene
  17. 29:53Numeric UDL operator templates
  18. 32:01Base 3 int revisited (helper templates)
  19. 36:28UDL operator templates: Nota Bene
  20. 38:10String UDL operator templates
  21. 39:47Example of a usable structural type
  22. 43:09IP addresses (continued)
  23. 44:22About UDLs in the standard library
  24. 45:06String UDLS
  25. 45:42Imaginary number UDLS
  26. 46:53Chrono duration UDLS
  27. 48:21The problem: type sinks
  28. 50:05Strong typedefs: the solution
  29. 52:20Extended numeric types
  30. 54:36Special-format string-like classes
  31. 55:06Physical units (continued)
  32. 56:09Can you obfuscate that better?
  33. 57:09A lot of work to support "magic" values
  34. 58:26Wait for the sign
  35. 59:13Aside: points vs. deltas
  36. 59:34Conclusions
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.