During code review I repeatedly found the following pattern in some other persons code:
void writeFile(std::string_view path)
{
auto of = std::ofstream(std::string{path});
...
}
As far as I understand, using string_view
in the functions signature avoids the string from being copied. Is there any point in using string_view
in the signature and then converting it to std::string
(and thus explicitly making a copy) in the next line? Isn't using a std::string
parameter achieving exactly the same?