~/talk

C++: Be type-safe - The journey of determining the number of elements in an array

Talkat NDC Oslo 2018 · 2018-06-11..06-15· [rust]
slides:none on file

Goal is a drop‑in, type‑safe way to get an array element count that fails at compile time. Implementation evolves from a macro to a constexpr function template that takes a const reference to T[N], then to a decltype/std::extent based approach combining std::extent + remove_reference and static_assert for clear errors. Pitfalls shown: sizeof trick misreports pointers, taking an address forces runtime, missing out‑of‑class static defs (C++11 vs C++17), and unit tests reveal edge cases; final options: std::array, span or the robust header-only helper that works across standards.

AI-written summary · about

  1. 0:00Start
  2. 7:57Type Safety
  3. 15:29Bonus Slides
  4. 27:31Error Message
  5. 35:40Final Solution
  6. 38:25Resize Helper
  7. 41:11Counting Array Elements at Compile Time
~/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.