gsl :: string_span`的目的是什么? [英] What purpose does `gsl::string_span` aim at?
本文介绍了gsl :: string_span`的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在阅读
During reading Microsoft's implementation of Cpp Core Guidelines, I run across two questions:
- 为什么在
gsl::span
已经正常工作的地方提供gsl::string_span
? - 为什么要提供
gsl::zstring_span
,因为自C ++ 11起已经保证std::string
以空值终止?
- 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.
推荐答案
-
span("Hi")
是{'H', 'i', '\0'}
,而string_span("Hi")
是{'H', 'i'}
.string_span
检查终止的空字符,并且不将其包括在范围中. -
string
是拥有的,而span没有,因此比较它们是比较苹果和橙子.zstring_span
是一个跨度,其约束是最后一个字符为空字符.span
和string_span
都没有那个约束.
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.
这篇关于gsl :: string_span`的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文