~/talk

std variant and the power of pattern matching

Talkat Meeting C++ 2018 · 2018-11-15..11-17· [rust]
links:none on file
slides:none on file

Shows that using std::variant plus an overloaded visitor yields exhaustive, type-safe handling of union-like cases and maps naturally to state machines and event objects. A mini space‑battle demo and an event-printing demo compile and run, but not zero cost: compile time +~200 ms, binary ~+1–2 KB, runtime +~1–3 ns in examples. Notes a real pitfall—dangling references when a handler mutates the variant—and the mitigation of returning an optional new state.

AI-written summary · about

  1. 0:00Intro
  2. 3:02Traditional: enum + state variables
  3. 5:07Wanted: Modeling states explicitly
  4. 6:03Definition: Sum Type
  5. 6:33Tagged Union
  6. 7:57Variant in C++ 17
  7. 8:50Getting at the current value
  8. 10:36Using std::visit()
  9. 12:06Matching values
  10. 13:41Native pattern matching: Haskell (1)
  11. 14:59Sum types & pattern matching
  12. 15:20Native pattern matching: Haskell (2)
  13. 16:16Native pattern matching: Rust
  14. 16:45Wanted: Pattern matching a C++ variant
  15. 17:04overloaded helper
  16. 18:45Writing a match() function
  17. 19:08Using the match() function
  18. 20:09Variant libraries
  19. 21:12Match function
  20. 22:41Reminder: Space game state machine
  21. 23:44Implementing state-specific logic
  22. 24:52State transitions: pitfall (2)
  23. 28:19Comparison
  24. 32:41Event handling
  25. 34:09Traditional approaches Event ID plus untyped payload (Win32 API)
  26. 41:22Recommendation
  27. 42:20More examples
  28. 45:38Native pattern matching proposal
  29. 53:04Space Game: Opponent state machine
  30. 56:05State transitions: pitfall (1)
~/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.