CppCoreGuidelines SL.str.12 用 s 后缀字面量标识标准库的字符串
27 December 2023
“Use the s
suffix for string literals meant to be standard-library
string
s”
理由
直接表达意图,避免误解。
例子
auto pp1 = make_pair("Tokyo", 9.00); // {C-style string,double} intended? pair<string, double> pp2 = {"Tokyo", 9.00}; // a bit verbose auto pp3 = make_pair("Tokyo"s, 9.00); // {std::string,double} // C++14 pair pp4 = {"Tokyo"s, 9.00}; // {std::string,double} // C++17