Now you might be thinking, what if we actually want to store the concatenated string as a new string rather than just compare it? What we do is simply overload an operator String() method so that the concatenation of the strings can implicitly convert itself to a string, like this:
struct ConcatProxy { const std::string& a; const std::string& b; operator String() const && { return String{a + b}; } }; auto func() { String c = String{"Marc"} + String{"Chagall"}; }
There is one little snag though; we cannot initialize the new String object with the auto keyword, as this would result in ConcatProxy:
auto c = String{"Marc"} + String{"Chagall"}; // c is a ConcatProxy due to the auto
Unfortunately, we have no way ...