From what I can gather, gsl::string_span
and std::string_view
seem to have essentially the same rationale for use. Is that indeed the case? If so, are they effectively identical? If not - how do they differ?
Related question: What purpose does `gsl::string_span` aim at?
A rather obvious difference of how they are available, but I'll say it since it is significant:
gsl::string_span
requires the use of a third party library, whilestd::string_view
is a standard C++ type. On the other hand, the library providinggsl::string_span
supports C++14, whilestd::string_view
requires C++17.A major design difference is that
std::string_view
is a const view to the string, and doesn't provide any way of modifying the viewed string, whilegsl::string_span
does allow non-const access. For example:Also note how
gsl::string_span
allows non-const access even when the span itself is const. in other words,gsl::string_span
does not propagate constness. This is the same asstd::span
andgsl::span
.