~/talk

The Many Shades of reference_wrapper

Talkat CppCon 2020 · 2020-09-14..09-18· [compilers-and-language-design]
links:none on file
slides:none on file

std::reference_wrapper models a rebindable reference that mimics language reference semantics while being a small pointer-sized type. It binds only to lvalues, accepts const and incomplete types, converts to T& and exposes assign through via get() so code can both rebind and assign through the same handle. It simplifies algorithms like linked-list remove by replacing pointer-to-pointer idioms and acts as a callable with constexpr callable like function pointers and constrained operator(), but it does not erase target types like std::function. Performance is roughly pointer-cost.

AI-written summary · about

  1. 0:00Introduction to reference_wrapper
  2. 1:56Why not use pointers
  3. 3:42Introducing reference_wrapper
  4. 8:47Assign-through and rebinding
  5. 10:13Linked list node removal
  6. 13:24Simplifying with reference_wrapper
  7. 17:05Reading file into linked list
  8. 18:36Function pointers comparison
  9. 20:46Reference wrapper as function pointer
  10. 23:55Type erasure limitations
  11. 25:20Summary and future
  12. 26:45Q&A session
~/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.