From Jason Turner
Watch on YouTube

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.

Resources

Tags