问题
During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions:
- Why is
gsl::string_spanprovided wheregsl::spanalready works well? - Why is
gsl::zstring_spanprovided wherestd::stringis 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_spanchecks for the terminating null character and does not include it in the span.stringis owning and spans are not, so comparing them is comparing apples and oranges.zstring_spanis a span with the constraint that the last character is a null character. Neitherspannorstring_spanhave that constraint.
来源:https://stackoverflow.com/questions/49348933/what-purpose-does-gslstring-span-aim-at