#include <string>
struct S
{
std::string s_;
std::string_view get() const &
{
return s_;
}
std::string_view get() const && = delete;
};
// I can't change this
struct T
{
T(std::string_view const sv); // does something safe with sv
};
// I can't change this
void f(std::string_view const &);
void g()
{
f(S{}.get()); // should compile
T t(S{}.get()); // should compile
std::string_view sv = S{}.get(); // should not compile
}
Is there way to use ref qualifiers without hindering usability as in the case above? In essence, it should prevent unsafe usage, but allow safe usage. I can wrap f
which does this, but it is unnecessary verbosity