Suggestion for the Result class


Hey, probably you may think i'm a bit stupid here... but the definition of the operator bool() in the Result class turned me mad for about some hours trying to understand what was going wrong. Look here:

const Result result(functionThatReturnsResult());
if (result.ok())

it took me hours to understand a simple typo, that ok() is not the same as wasOk()...

i think it's a good idea to be on the safe side and trigger a compiler error if one try to do this !



Nasty! In fact the best way to fix this would be to somehow prevent a static method being called accidentally on an actual object.. Unfortunately I don't know of any way to do that!

The reason I added the bool operator in the first place was so that I could change the return type of a bunch of methods from bool to Result without breaking any existing code. Removing the operator is a good idea - it's just one of those things where we have to balance inconvenience against safety.


+1 , I'd say safety trumps inconvenience in all cases.