~/talk

How to Use string_view in C++ - Basics, Benefits, and Best Practices

Talkat CppCon 2024 · on Tuesday, 2024-09-17· at 15:15· Cottonwood 8/9, 6700 North Gaylord Rockies Boulevard· [c-and-cpp]
links:none on file
links:none on file
slides:none on file

string_view is a lightweight pointer+length view that avoids heap allocation for many APIs but string_view is pointer+length and not null terminated so C functions and implicit conversions bite. C++17/20/23 add useful constructors and the ""sv literal skips strlen but permits embedded NULs. Use std::span for contiguous containers (std::span for contiguous containers), prefer passing by value, and avoid returning views into temporaries. Add a transparent comparator for map<string,int> lookups from string_view and enable clang/MSVC dangling/lifetime warnings; case study swaps vector<string> for span<string_view> and removes runtime allocations.

AI-written summary · about

  1. 0:00Intro
  2. 1:30Motivation
  3. 14:20Stringview vs string
  4. 17:33Stringview interoperability
  5. 25:13Problems with stringview
  6. 30:00Stringview from templates
  7. 47:20Case Study
  8. 54:32Wrap Up
  9. 55:52Special Thanks
  10. 56:25Questions Comments
  11. 58:22Questions Answers
~/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.