Description:
std::string_view (C++17) is a non-owning read-only view of a sequence of characters. This can be beneficial in reducing unecessary copies of character data when passing strings into functions or performing parsing (e.g. using the .substr function). String views don't allocate the character data; they refer to an existing character sequence.
However there are a couple of pitfalls to be aware of. As string_view is a simple view of existing data, the data which it refers to must remain valid for the duration of the string_view. I give an example here of returning a string_view from a function where the underlying string data is destroyed on return.
Share this link via
Or copy link























