~/talk

The Fine Details Behind C++ Containers And Algorithms

Talkat CppNorth 2022 · 2022-07-18..07-20· [c-and-cpp]
slides:none on file

The C++ library requires vector::push_back to be amortized O(1) and benchmarks show forgetting noexcept on move constructors causes large slowdowns due to copy instead of move. Sorting a list is faster if copied to a vector first because cache locality wins; tests include full copy+sort+copy measured. Erasing many indexed elements is faster by moving blocks then one shrink rather than repeated erase. unordered_map find can be worst‑case O(n) (hash collisions/attacks). C++17 features like try_emplace/insert_or_assign and node_handle extract/insert measurably reduce allocations; ranges and parallel algorithms help sometimes but always benchmark.

AI-written summary · about

  1. 0:00Introduction and speaker intro
  2. 1:10Talk overview and topics
  3. 1:51Vector push_back complexity explained
  4. 5:28Vector resizing and noexcept move constructors
  5. 6:51std::copy and memory handling
  6. 8:14Container complexity in C++ spec
  7. 9:39Sorting vector vs list performance
  8. 14:38Inserting elements at front of vector
  9. 16:25std::move vs std::move in algorithms
  10. 17:07Erase-remove idiom explained
  11. 19:15C++20 erase function for containers
  12. 19:36Erasing elements by index from containers
  13. 24:17Complexity of unordered_map insert
  14. 27:51Hash function performance and attacks
  15. 28:16Dangling references and temporary objects
  16. 30:07C++17 insert_or_assign vs insert
  17. 33:03C++17 in_place and try_emplace for maps
  18. 36:15C++17 node_handle for map nodes
  19. 38:43C++17 try_emplace with hint
  20. 40:07C++17 string_view and ranges introduction
  21. 41:56C++23 flat_map and data locality
  22. 43:20Loop efficiency and cache locality
  23. 45:08C++20 ranges and lazy evaluation
  24. 46:13C++17 parallel algorithms overview
  25. 47:17Thread safety in C++ containers
  26. 48:41Iterator invalidation rules
  27. 49:45std::iterator deprecation
  28. 50:48Reverse iterator implementation details
  29. 52:17Summary and best practices
  30. 57:16Q&A on container runtime changes
~/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.