Closed qknight closed 4 years ago
with this example below, copied from the Readme.md we assign:
SYSTEM_ERROR2_CONSTEXPR14 auto v = another_namespace::status_code(another_namespace::AnotherCode::success1); SYSTEM_ERROR2_NAMESPACE::error err = v;
This terminates the program according to the check in the source in status_code.hpp!
We wonder why should I use SYSTEM_ERROR2_NAMESPACE::error vs. SYSTEM_ERROR2_NAMESPACE::status_code at all? When does it make sense to use
::error
and when to use::status_code
The relationship here is as follows:
system_code
is a status_code
erased into an intptr_t
.error
is an errored_status_code
erased into an intptr_t
.errored_status_code
is a status_code
for whom it is guaranteed that .success()
is false, which was originally going to be guaranteed using C++ contracts before those got axed. The next closest equivalent to Contracts is terminating the process.So the idea is that an operation can return a status code which may be successful (e.g. with warning or additional info), or may be a failure with cause. If you wish to promise in the C++ type system that a status code will always be a failure, you use errored_*
or error
. The compiler may be able to make extra optimisations in this situation (no current compiler can).
Hopefully that makes sense.
Re: adding the quick status code from enum example, no problem I'll do that there now.
Hey,
with this example below, copied from the Readme.md we assign:
This terminates the program according to the check in the source in status_code.hpp!
We wonder why should I use SYSTEM_ERROR2_NAMESPACE::error vs. SYSTEM_ERROR2_NAMESPACE::status_code at all? When does it make sense to use
::error
and when to use::status_code
Readme.md (the source code with small adaptions)
Additional wish
Could you add this code to the examples/ folder also?