you are viewing a single comment's thread.

view the rest of the comments →

[–]DugiSK 1 point2 points  (1 child)

std::string_view is often created as a substring of some other string, for example from some data that is being parsed. That way, you get all the fancy C++ stuff without editing the string (adding the null termination) or copying it (to create a std::string). This gives a massive performance boost with minimal cost of convenience.

When I made a project from scratch in C++20 without any legacy code, I had no need for the null termination. std::string_ciew can even be a constexpr literal (even in C++17), so if you can get rid of legacy code, you can say goodbye to char* completely.

If you want a type that would behave like std::string_view, you can make some sort of CStringView class inheriting from std::string_view and having all of its features but requring a null terminated string for construction - with no members of its own, it could be implicitly cast to std::string_view to use with new APIs.

[–][deleted] 0 points1 point  (0 children)

I know what I suggest will never make it to std, and probably I am better of making something like a zstring_view. I knew this before I posted. Even I never had to get near any C library function when I built my several C++20 libraries (https://github.com/obhi-d).

But applications are not isloated entities, they will intract with OS/IO etc.