SL.str.2:使用std::string_view或gsl::span<char>参照字符序列
std::string_view or gsl::span<char> provides simple and (potentially) safe access to character sequences independently of how those sequences are allocated and stored.
std::string_view或者gsl::span<char>可以简单且(潜在地)安全地访问字符串而不需要关心这些序列是如何分配和存储的。
Example(示例)
vector<string> read_until(string_view terminator);
void user(zstring p, const string& s, string_view ss)
{
auto v1 = read_until(p);
auto v2 = read_until(s);
auto v3 = read_until(ss);
// ...
}
std::string_view (C++17) is read-only.
std::string_view(C++17)是只读的。
Enforcement(实施建议)
???
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#slstr2-use-stdstring_view-or-gslspanchar-to-refer-to-character-sequences