Summary
This episode explores std::string_view, a new C++17 feature that provides a non-owning reference to a sequence of characters. Jason demonstrates how string_view avoids unnecessary memory allocations when compared to std::string by simply storing pointers to the beginning and end of a string. Using compiler explorer examples, he shows that operations like getting a string's length can be much more efficient with string_view, especially when working with constant string literals, as the compiler can optimize away temporary allocations that would otherwise occur with std::string.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[string.view]74% match -
[diff.cpp20.strings]59% match -
[string.substr]43% match