What purpose does `gsl::string_span` aim at?

自古美人都是妖i 提交于 2020-02-04 02:54:29

问题


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.


回答1:


  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.


来源:https://stackoverflow.com/questions/49348933/what-purpose-does-gslstring-span-aim-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!