I would like to use an equivalent of std::pair<bool, std::string>
as a function return type. In downstream code it would look better to use ok
and msg
instead of first
and second
accessors to avoid unnecessary API lookup. And I don't seem to be able to write it correctly using inheritance as std::pair
may leak without virtual destructor. Wanted to avoid my own struct as the solution in Renamed std::pair members - to reuse existing Move constructor and other plumbing. Is it possible at all?
Edit:
After the feedback seems to be that the recommended way to go is:
struct res {
bool ok;
std::string msg;
};
res fnk() { ...; return r };
Do I understand correctly that C++11 compiler expected to generate the move constructor to avoid copying the string?