问题
Will C++17 contain a literal suffix for const char* to std::string_view conversion?
auto str = "asdf"s;
Will the type of str in the above statement be std::string or std::string_view?
回答1:
If we're to believe STL's comment, then yes, we'll have string view literal suffixes based on, I believe, P0403R0.
If I understand things correctly s will stay a std::string literal suffix, while std::string_view will use sv.
cout << "Hello, string_view literals!"sv << endl;
cout << "Hello, string literals!"s << endl;
As of this commit sv is in the Standard C++ draft.
来源:https://stackoverflow.com/questions/40667681/c17-operators-for-string-view