~/talk

OLD VERSION: Understanding The constexpr 2-Step

Talkat C++ on Sea 2024 · 2024-07-02..07-05· [compilers-and-language-design]
slides:none on file

C++20 makes std::vector and std::string usable in constant expressions yet direct constexpr heap allocation fails because memory allocated at compile time must also be freed at compile time. The practical solution is the constexpr two-step: perform dynamic work at compile time, copy into an oversized array stored as a compile-time template value, then create a right-sized static copy and return a span or string_view. Examples include a 300-angle table (shows 1,696 unused zeros if oversized) and a clang bug around static inside consteval fixed by using an NTTP value.

AI-written summary · about

  1. 0:00constexpr two-step concept
  2. 3:02C++20 containers and memory rules
  3. 10:58constexpr two-step technique
  4. 17:02Level one: oversized array
  5. 27:04Level one review and binary size
  6. 35:54Level two: string to string_view
  7. 42:25Level 2.5: span and string_view
  8. 51:19Right-sizing arrays
  9. 57:00Level three: vector to span
  10. 1:00:13Summary and applications
~/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.