gsl :: string_span`的目的是什么? [英] What purpose does `gsl::string_span` aim at?

查看:242
本文介绍了gsl :: string_span`的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读微软的实现期间/CppCoreGuidelines/CppCoreGuidelines"rel =" nofollow noreferrer> Cpp核心指南,我遇到两个问题:

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

  1. 为什么在gsl::span已经正常工作的地方提供gsl::string_span?
  2. 为什么要提供gsl::zstring_span,因为自C ++ 11起已经保证std::string以空值终止?
  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.

推荐答案

  1. span("Hi"){'H', 'i', '\0'},而string_span("Hi"){'H', 'i'}. string_span检查终止的空字符,并且不将其包括在范围中.
  2. string是拥有的,而span没有,因此比较它们是比较苹果和橙子. zstring_span是一个跨度,其约束是最后一个字符为空字符. spanstring_span都没有那个约束.
  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.

这篇关于gsl :: string_span`的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆