3 ms·
In the presence of types which are truthy (ie, contextually convertible to bool), its too easy to accidentally swap the unpacking: // Oops, backwards!
by brandmeyer 5y ago
In the presence of types which are truthy (ie, contextually convertible to bool), its too easy to accidentally swap the unpacking:
// Oops, backwards!
auto [result, error_code] = do_something();
if(error_code) {
process(result);
}
- BoorishBears 5y agoTo me that's not easy... It's a very well established pattern to have (error, result) I'd immediately see something off with (result, error) And clang-tidy can catch this: https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html https://clang.llvm.org/extra/clang-tidy/checks/readability-i...
- Kranar 5y agoFair enough, in my codebase we always order data in terms of dependencies so that independent data comes before dependent data. In this case the result depends on the error_code, and the error_code is independent, so the error_code must be listed first.