你怎么不用string_view举例呢?
给一个absl的例子:
// Splits the given string on commas. Returns the results in a
// vector of strings. (Data is copied once.)
std::vector<std::string> v = absl::StrSplit("a,b,c", ','); // Can also use ","
// v[0] == "a", v[1] == "b", v[2] == "c"
// Splits the string as in the previous example, except that the results
// are returned as `absl::string_view` objects, avoiding copies. Note that
// because we are storing the results within `absl::string_view` objects, we
// have to ensure that the input string outlives any results.
std::vector<absl::string_view> v = absl::StrSplit("a,b,c", ',');
// v[0] == "a", v[1] == "b", v[2] == "c"
【 在 hgoldfish 的大作中提到: 】
: cpp 多半不会搞 cow, 因为 cow 内部其实是个 shared_ptr<>,按 cpp 的传统艺能,应该弄个 unique_ptr<> 或者 std::move() 效率更高嘛。shared_ptr<> 弱爆了。
: stringview 的用途是 split()
: QVector<QStringRef> parts = s.splitRef(":");
: ...................
--
FROM 76.126.252.*