What purpose does `gsl::string_span` aim at?
Asked Answered
S

1

7

During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions:

  1. Why is gsl::string_span provided where gsl::span already works well?
  2. Why is gsl::zstring_span provided where std::string is already guaranteed to be null-terminated since C++11?

Any illustrating situations will be highly appreciated.

Saturate answered 18/3, 2018 at 14:22 Comment(3)
Have you read the comments above basic_zstring_span?Sinew
I've read the comment you cited. However, I'm still unclear.Saturate
@Saturate What about the comment do you understand?Forefoot
U
7
  1. span("Hi") is {'H', 'i', '\0'} whereas string_span("Hi") is {'H', 'i'}. string_span checks for the terminating null character and does not include it in the span.
  2. string is owning and spans are not, so comparing them is comparing apples and oranges. zstring_span is a span with the constraint that the last character is a null character. Neither span nor string_span have that constraint.
Unspeakable answered 19/3, 2018 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.