I am aware that std::string_view
is a non-owning reference to a string and the major differences between std::string_view
and std::string
are
Now, Why std::string_view is not applicable to other types ? or why this implementation is specific ONLY to std::string
?
For Example : if we have similar <T>generic_view
where T
can be of any type including custom types.
With this, instead of using const T&
as function argument, <T>generic_view
can be used. And also other advantages of std::string_view
will be useful like Allocation, Copying etc..
There is a non-owning type for contiguous collections of arbitrary objects in C++20 called std::span
.
Versions of C++ prior to C++20 can use the standalone implementation gsl::span
.
std::span
behaves similarly to C++17's std::string_view
, but the interface provides general container-like access instead of string-like access, and the underlying data can be non-const
. (From the table in the question, Element Mutability is Allowed.)
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