18 Oct
2021
18 Oct
'21
1:05 a.m.
Andrey Semashev wrote:
Remember that libraries also need to return string_views.
Yes. Depending on the case, this can be worked around too. For example, have a convention that if you accept a string_view, you return the same kind of string_view as well.
And now all code that used to pass string literals or std::strings is broken because of ambiguity. And if you add overloads to fix the ambiguity (remember that the whole purpose of string_view is to let you get by without adding overloads), you can't return both string views at once.
If you don't accept a string_view, let the user choose what he wants. Pick a default, if that's too verbose.
How would that work, exactly? Take the example function signature and show us how it's done.