Can string_views be used in combination with setters?
I would like to have something like the code below. Unfortunately, my constructors are ambiguous for the second invocation. The view is capable of reducing the number of methods, std::string, C string, but could it be used as well in combination with move semantics? Or is the view solely intended for "you may look at the string, but you are not allowed to own it."?
#include <iostream>
#include <string>
#include <string_view>
using namespace std;
struct Str {
explicit Str(string_view str)
: m_str(str) {}
explicit Str(string &&str)
: m_str(std::move(str)) {}
string m_str;
};
int main() {
string a = "a";
Str as = Str(a);
Str bs = Str("b");
}
↧