16 Jan
2018
16 Jan
'18
5:09 p.m.
Andrey Semashev wrote:
Calling (virtual) `error_category::failure` early is a waste if the user doesn't want to call that function himself. For instance, he may want to test specific error codes instead.
It can still be worth it because it's more likely to occur in a context where the compiler can see what category is being used. When you have error_code ec( r, system_category() ); and system_category() is constexpr, the compiler knows with certainty what the call category().failed( r ) will do, so it will replace it with r != 0.