What about:
string MakeData(string const&) { ... return string(...);
followed by
int main() { string const& str = MakeData("Something that makes sense to humans"); }
The difference with what you do is using a const reference and only one function. If you cannot change MutateData , do what you suggested (with a constant reference)
source share