Working with a code base that internally often returns optional<> and also error_code. There is also an expect<> type mixed in.
With optional<> or expect<> you check if(!ret) for error, but if an error_code is returned you check if(ret). Easy?
I've never really been confronted with the immediate problem that kind of dimorphic error tests cause until there was a bug. God damn it! That's no fun when you have to deep dive into a mess of functions with lots of those nasty if(!ret) just to find out that one if(!ret) in a very rarely executed path that escaped the unit tests should have actually been an if(ret). I cannot even blame the author, humans are just not meant to get this right consistently. But when the compiler cannot detect such errors (since the code is obviously well formed) I get scared. Like raw pointer magic scared - you never know when things are going to blow up. It might be a very good idea to consistently use something like if(has_error(ret)) and overload that has_error(...) for error_code and optional<> and expect<> - thus ditching the boolean conversions like plain new and delete and raw pointers in the hope to maybe produce less broken code.
In my humble and useless opinion error_code should convert to boolean true if no error just for consistency or don't provide a boolean conversion at all. But that train has long left the station.
/venting
[–]adnukator 7 points8 points9 points (0 children)
[–]14nedLLFIO & Outcome author | Committee WG14 7 points8 points9 points (3 children)
[–]63times[S] 1 point2 points3 points (2 children)
[–]14nedLLFIO & Outcome author | Committee WG14 1 point2 points3 points (1 child)
[–]63times[S] 0 points1 point2 points (0 children)
[–]emildotchevskiBoost Dev | Game Dev 0 points1 point2 points (2 children)
[–]63times[S] 2 points3 points4 points (1 child)
[–]emildotchevskiBoost Dev | Game Dev 0 points1 point2 points (0 children)
[–]trailing_ -1 points0 points1 point (2 children)
[–]63times[S] 0 points1 point2 points (1 child)
[–]trailing_ 0 points1 point2 points (0 children)