~/talk

Fun with Type Erasure: Implementing a Value Wrapper for Polymorphic Types

Talkat C++ on Sea 2021 · 2021-06-30..07-02· [c-and-cpp]
links:none on file
slides:none on file

Builds a minimal type‑erased value wrapper that gives polymorphic objects value semantics instead of pointer semantics, implementing a union for 24-byte SSO, a static function-table with destroy/copy/move/assign per concrete type, and an optional pointer-to-interface cache to speed value access. It chooses small vs big storage by size and noexcept moveability, implements placement‑new in‑place construction, copy/move/assign with weak/strong exception guarantees, and compares behavior and sizes against std::any implementations — it works and trades a few bytes for much cheaper runtime access.

AI-written summary · about

  1. 0:00Start
  2. 1:22The idea
  3. 1:45Pointer semantics
  4. 4:43Value semantics?
  5. 10:21Basic solution: drawbacks
  6. 18:00Minimal implementation
  7. 26:45Let's save pointer to interface
  8. 29:12Comparison to std::any
  9. 34:05Let's move!
  10. 38:09Differences to std:: any
  11. 46:08Assignment support
  12. 53:00Value assignment
~/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.