How useful it could have been if...

I’m writing tests for some code. I have a function that I’m testing that looks something like this:

bool CAsyncSocket::Read(bool throwOnFailure = false);

If C++ allowed us to overload a function call based on return type then we wouldn’t need the horrible throwOnFailure wart and the compiler could pick the right version depending on if we try to use the return value or not… So a call like this: bool ok = pSocket->Read(); would return errors and a call like this: pSocket->Read(); would throw exceptions…

I know why C++ doesn’t support overloads on return type and I accept that the above could be confusing but…

I suppose the way around it is to call the functions different things;

void CAsyncSocket::Read();

bool CAsyncSocket::TryRead();

Hmm… Undecided…