Recently, during code review, I stumbled upon the std::string_view argument passed by reference. So for example the following code:
void fun(std::string_view a);
becomes
void fun(std::string_view& a);
I found it troubling for the following reasons:
- It can no longer be invoked with anything other than
l-valuestd::string_view. - The whole point of using
std::string_viewis about avoiding copying the underlying string, so I see no point of using&with it.
The question is, Is there any advantage of declaring std::string_view argument as passed by reference instead of passed by value?