How do gsl::string_span
and std::string_view
differ?
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, while std::string_view
is a standard C++ type. On the other hand, the library providing gsl::string_span
supports C++14, while std::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, while gsl::string_span
does allow non-const access. For example:
constexpr iterator gsl::string_span::begin() const noexcept
^^^^^^^^ note non-const iterator ^^^^^ also note this
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 as std::span
and gsl::span
.
gsl::string_view
have been an endeavor to mimic the comingstd::string_view
? How come they diverged on something as significant as deep vs shallow constness? – Whiskey