~/talk

Polymorphism with Unions

Talkat CppCon 2014 · on Thursday, 2014-09-11· at 09:00· Euler· [rust]
links:none on file
slides:none on file

Argues that tagged unions replace brittle class hierarchies by collapsing finals into a value type with a vtable-like tag, shows a C++14 implementation on GitHub that uses overloaded lambdas to implement multi-method dispatch and a configurable nullable variant state. Demonstrations include a compiler-style example and a small interpreter, the implementation actually runs, and measured dispatch costs are nontrivial (roughly up to half as fast or somewhat worse than virtual calls) but acceptable outside hot loops.

AI-written summary · about

  1. 0:00Start
  2. 0:39Class Hierarchy
  3. 2:33Visitor Pattern
  4. 14:00Overloaded Lambda
  5. 16:51Tagged Union
  6. 25:45Group Virtual Behaviors out of Animals
  7. 40:36Multi Dispatch
  8. 43:12Difference between a Vector of Unions or a Tuple
  9. 48:31Options for Improving the Performance
  10. 50:27And We Can Have a Forward Declaration of Expression at that Point That We Finalize Eventually with the Union So Exactly the Same Thing You Would Do if It Weren't Union Yeah We Do in Fact so My My Backups Live if I Had Slides Here's an Entire Language Interpreter Written with Yeah Simple Calculator Written with a Union for Values and Union for Expressions and It Actually Works So and It's Actually Pretty Short Considering Yeah Well I Didn't Have As Much Time before this Conference as I Thought I Was Going To Huh I Try To Remember To Go In and Comment Things and So I Leave Nag Messages for Myself
  11. 53:03It Would Be Possible To Do that the Problem Is I Need some State To Copy or Steal To Initialize the Variant So if You Create a Dog as an R-Value Reference I Can Move It and Then It's My Variant Dog if You Just Say I Want a Dog by Name Then I Need some Kind of a Factory so We Could Build a Factory Pattern around this As Well It Would Just Be Something That Sits on Top It Wouldn't Really Change this At All I Can Talk to You about It Afterward if You like Anybody Else I Think Okay the Question Is whether It Works like Pattern Matching and Is Therefore Not Order Dependent It Is Not Order Dependent It Works like Pattern
  12. 55:20It's It's Doable the Point Is Sometimes You'Re Going To Do Inheritance for Classification for Behavior and Sometimes You'Re Going To Do It for Construction of the Type Basically It's a Form of Aggregation so You'Re Going To Stick Things in but Not Be Them for the Purpose of an Algorithm That's Fine You Can You Can Certainly Do that and Then those Bases Later You Could Match on if You Wanted To with the with an Overloaded Lambda but You Could Overlook You Could Do the Overloaded Lambda on Anything That Would Be Statically Discernibly Different about the Type Absolutely So for Example though the Right like I Want To Stream this Variant out the Simplest Case Right You Just Have a Single Auto That Whatever It Is I Shove It onto an Out Stream and It's Fine Right because They all They all Provide Their Own Overloads for Doing that
~/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.