Suppose I have a class whose internal data representation is, for example std::string,:
class my_type {
std::string m_value;
...
};
Would it be nice if I could "infer" an internal representation my_type? This ability will be performed in such a way as:
class my_type {
std::string m_value;
public:
operator std::string() && {
return std::move(m_value);
}
};
...
my_type val;
std::string str1 = std::move(val);
std::string str2 = a_func_that_returns_my_type();
DIRECT EXAMPLE
Concrete questions:
Out of BadIdea ™? S internal view? (e.g. leaking implementation?)
Am I abusing the use of the (implicit) conversion operator? If so, should an explicit option be used? Example:
std::string str = std::move(val).get_str();
or
auto str = val.move_str_out();
Should I define it if there is an existing conversion operator / function for l-values?
Am I trying to achieve what I am trying to achieve, premature optimization?
For more information see: