Is it possible to set default param value for the std::string_view?

Viewed 62

Is it safe to set an empty default value for the std::string_view?

void func(std::string_view arg = {} )
1 Answers

It's allowed to create an empty std::string_view the same way it's allowed to create an empty std::string for example.

Of course, if your function intends to do some direct access operations (for example std::string_view::front() or std::string_view::back()), in that case, it will be necessary to check if the std::string_view is not empty beforehand (std::string_view::empty()).

Related