C++17 operator“”s for string_view?

。_饼干妹妹 提交于 2021-02-08 12:16:40

问题


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

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