A string_view is:
An object that can refer to a constant contiguous sequence of
char-like objects with the first element of the sequence at position zero.A typical implementation holds only two members: a pointer to constant
CharTand a size.
This allows for robust but lightweight inspection of a string. It's perfect for recursive functions that would otherwise be forced to work with char*s or string::iterators to pare down a string.
My question is what about other containers? Why provide this only for string? What about other contiguous containers, such as vector, map, queue, etc?
A std::string_view is to a pair of iterators as a std::string is to a standard container of char.
In other words, we can use pairs of iterators (or in future, a standard range object) to represent views into standard containers.
The string-view provides extra, string-like functions that mostly parallel the extra, string-like functions that are part of std::string. For other containers, the equivalent operations are generally constructed from standard <algorithm> functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With