Base class providing standard status operations for status types using CRTP.
StatusBase provides common functionality for status types that wrap an enum or integer status code, including checking for success (ok()), retrieving the code (code()), string formatting (str()), updating, and equality comparisons.
Custom status types should derive from StatusBase<Derived, kOkCode> or use the PW_STATUS_TYPE macro. Derived classes should be declared [[nodiscard]] unless created using PW_STATUS_TYPE (which applies [[nodiscard]] automatically).
Users should not interact directly StatusBase, except to instantiate a custom status class. Do not use StatusBase for variables or function parameters.
| Derived | The derived status class (CRTP parameter). |
| kOkCode | Code value that represents success (ok() == true). |
Public Types | |
| using | Code = decltype(kOkCode) |
| The underlying status code type. | |
Public Member Functions | |
| constexpr bool | ok () const |
| Returns true if the status is the OK code. | |
| constexpr Code | code () const |
| Returns the underlying status code. | |
| constexpr void | Update (Derived other) |
| constexpr void | IgnoreError () const |
| Ignores any errors, suppressing unused-result warnings. | |
| constexpr const char * | str () const |
Protected Member Functions | |
| constexpr | StatusBase () |
Defaults to kOkCode (ok() == true). | |
| constexpr | StatusBase (Code code) |
| Explicitly construct from the underlying code. | |
| constexpr | StatusBase (const StatusBase &)=default |
| constexpr StatusBase & | operator= (const StatusBase &)=default |
| constexpr | StatusBase (StatusBase &&)=default |
| constexpr StatusBase & | operator= (StatusBase &&)=default |
Protected Attributes | |
| Code | code_ |
Friends | |
| constexpr bool | operator== (Derived lhs, Derived rhs) |
| constexpr bool | operator!= (Derived lhs, Derived rhs) |
| constexpr bool | operator== (Derived lhs, Code rhs) |
| constexpr bool | operator== (Code lhs, Derived rhs) |
| constexpr bool | operator!= (Derived lhs, Code rhs) |
| constexpr bool | operator!= (Code lhs, Derived rhs) |
|
inlineconstexpr |
Returns a string representation of the status. Only supported for status types with enum codes.
|
inlineconstexpr |
Updates this status to other if this status is currently ok().
This is useful for tracking the first encountered error, as calls to this helper will not change one error status to another error status.