~/talk

Everyday Efficiency: In-Place Construction (Back to Basics?)

Talkat CppCon 2019 · 2019-09-15..09-20· [developer-experience]
slides:none on file

Everyday rules for avoiding needless copies and allocations: string moves often cost as much as copies (bench shows ~20% slower moves for small strings), copy elision/RVO is the primary optimization to rely on, and push_back is fine for rvalues while emplace_back truly avoids temporaries. Associative containers need piecewise_construct for multi-arg mapped types, initializer_list can cause initializer_list undefined behavior and prevents moves, and optional/variant provide in-place constructors that prevent extra construction and moves.

AI-written summary · about

  1. 0:00Introduction and talk overview
  2. 3:02What is in-place construction?
  3. 5:16Return Value Optimization (RVO) explained
  4. 8:08Rules and pitfalls of RVO
  5. 10:19RVO examples and compiler differences
  6. 14:31Named RVO and compiler behavior
  7. 15:52Common anti-patterns with RVO
  8. 17:39Why avoid default construction?
  9. 18:00Vector: push_back vs emplace_back
  10. 21:34Vector in-place construction with parameter packs
  11. 23:29Vector in-place construction with explicit constructors
  12. 25:17Vector in-place construction pitfalls
  13. 26:43Pairs and multi-argument constructors
  14. 28:50Recommendations for vectors
  15. 29:11Initializer lists and their issues
  16. 34:14Recommendations for initializer lists
  17. 34:35Maps: complexity and interfaces
  18. 36:04Vittorio's foreach-n-args for maps
  19. 37:50Inserting into existing maps
  20. 41:47Map in-place construction pitfalls
  21. 42:48Multi-argument constructors in maps
  22. 44:38Emplacing function results in maps
  23. 46:48Map insert_or_assign in C++17
  24. 47:53Map interface complexity summary
  25. 49:00C++20 aggregate initialization in maps
  26. 50:07Try_emplace for maps
  27. 51:37Optional, variant, and any in-place construction
  28. 53:27Recommendations for optional and variant
  29. 55:41Variant narrowing conversions in C++20
  30. 57:05Summary and best practices
~/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.