How to pass std::string_view by value or by const reference

Viewed 1112

Usually string_view is used for function parameters like this:

void fval(std::string_view sv);
void fcref(std::string_view const &sv);

Which is better?

const reference is 8 bytes and string_view is usually twice that, e.g. 16 bytes.

However, if not inlined or optimized away, const reference might have two indirections - one for the ref, second for the pointer inside.

How STL doing it?

1 Answers
Related