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?
How do
gsl::string_spanandstd::string_viewdiffer?
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.
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