~/talk

How to Remove Negative Numbers From C++ Containers

Talkat C++Online 2025 · 2025-02-26..02-28· [c-and-cpp, developer-experience]
slides:none on file

Shows concrete recipes: use erase_if vs remove_if + erase for vectors, use ranges::views::filter and views::keys/values for maps, write templates constrained by concepts to accept numeric types, and prefer std::strong_order or isnan handling for doubles because NaNs break comparisons. Notes arrays can’t shrink so you must copy or transform, explains nth_element/partition for fewer moves, warns about signed/unsigned promotion traps and offers a randomized sampling and a recursive filter as experimental alternatives.

AI-written summary · about

  1. 0:00Introduction and motivation
  2. 2:58Basic removal with initializer list
  3. 4:22Erase if vs remove if
  4. 6:30Generalizing with templates
  5. 9:51Testing and constraints
  6. 14:32Handling other containers
  7. 16:17Arrays and fixed-size containers
  8. 18:03Working with maps
  9. 20:33Ranges and views
  10. 23:49Silly approaches
  11. 25:14Removing everything
  12. 26:16Shifting values to zero
  13. 28:26Counting and sorting negatives
  14. 30:16Using nth element
  15. 31:45Partitioning containers
  16. 34:35Recursive removal
  17. 37:28Bogo sort inspired removal
  18. 41:07Handling NaN values
  19. 44:04Signed vs unsigned comparisons
  20. 46:13Summary and best practices
  21. 49:26Q&A and closing remarks
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 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
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
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.