问题
During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions:
- Why is
gsl::string_span
provided wheregsl::span
already works well? - Why is
gsl::zstring_span
provided wherestd::string
is already guaranteed to be null-terminated since C++11?
Any illustrating situations will be highly appreciated.
回答1:
span("Hi")
is{'H', 'i', '\0'}
whereasstring_span("Hi")
is{'H', 'i'}
.string_span
checks for the terminating null character and does not include it in the span.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. Neitherspan
norstring_span
have that constraint.
来源:https://stackoverflow.com/questions/49348933/what-purpose-does-gslstring-span-aim-at