A wrapper class for system error codes with additional context.
More...
#include <error_utils.hpp>
|
constexpr | Error () noexcept=default |
|
constexpr | Error (const std::error_code &code, const std::string_view context={}) |
| Create an error with the specified error code and optional context.
|
|
constexpr | Error (const detail::convertible_to_error_code auto code, const std::string_view context={}) |
| Create an error with a type convertible to std::error_code and optional context.
|
|
constexpr | Error (const Error &other) noexcept=default |
|
constexpr | Error (Error &&other) noexcept |
|
constexpr Error & | operator= (const Error &other) |
|
constexpr Error & | operator= (Error &&other) noexcept |
|
| ~Error () noexcept=default |
|
constexpr | operator bool () const noexcept |
| Implicit conversion to bool, indicating whether an error exists.
|
|
constexpr const std::error_code & | error_code () const noexcept |
| Returns a constant reference to the underlying error code.
|
|
constexpr const std::string & | context () const noexcept |
| Returns a constant reference to the context string.
|
|
constexpr int | value () const noexcept |
| Returns the value of the error code.
|
|
constexpr const std::error_category & | category () const noexcept |
| Returns the category of the error code.
|
|
constexpr std::string | message () const |
| Get the error message including context if available.
|
|
template<typename T>
requires detail::comparable_to_error_code<T> |
constexpr bool | is (T &&code) const noexcept |
| Check if the error is of a specific type.
|
|
template<typename Code, typename... Others>
requires detail::comparable_to_error_code<Code> && (detail::comparable_to_error_code<Others> && ...) |
constexpr bool | is_any_of (Code &&code, Others &&... others) const noexcept |
| Check if the error belongs to any of the specified error codes or error conditions.
|
|
|
constexpr friend bool | operator== (const Error &lhs, const Error &rhs) noexcept |
|
constexpr friend auto | operator<=> (const Error &lhs, const Error &rhs) noexcept |
|
constexpr friend bool | operator== (const Error &lhs, const std::error_code &rhs) noexcept |
|
constexpr friend auto | operator<=> (const Error &lhs, const std::error_code &rhs) noexcept |
|
constexpr friend bool | operator== (const Error &lhs, const std::error_condition &rhs) noexcept |
|
constexpr friend std::ostream & | operator<< (std::ostream &os, const Error &obj) |
|
constexpr friend void | swap (Error &lhs, Error &rhs) noexcept |
| Swap the contents of two Error objects.
|
|
A wrapper class for system error codes with additional context.
◆ Error() [1/5]
error_utils::Error::Error |
( |
| ) |
|
|
constexprdefaultnoexcept |
◆ Error() [2/5]
error_utils::Error::Error |
( |
const std::error_code & | code, |
|
|
const std::string_view | context = {} ) |
|
inlineexplicitconstexpr |
Create an error with the specified error code and optional context.
- Parameters
-
code | The system error code |
context | Additional context information about the error |
◆ Error() [3/5]
error_utils::Error::Error |
( |
const detail::convertible_to_error_code auto | code, |
|
|
const std::string_view | context = {} ) |
|
inlineexplicitconstexpr |
Create an error with a type convertible to std::error_code
and optional context.
- Parameters
-
code | The error code |
context | Additional context information about the error |
◆ Error() [4/5]
error_utils::Error::Error |
( |
const Error & | other | ) |
|
|
constexprdefaultnoexcept |
◆ Error() [5/5]
error_utils::Error::Error |
( |
Error && | other | ) |
|
|
inlineconstexprnoexcept |
◆ ~Error()
error_utils::Error::~Error |
( |
| ) |
|
|
defaultnoexcept |
◆ category()
const std::error_category & error_utils::Error::category |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns the category of the error code.
◆ context()
const std::string & error_utils::Error::context |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns a constant reference to the context string.
◆ error_code()
const std::error_code & error_utils::Error::error_code |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns a constant reference to the underlying error code.
◆ is()
template<typename T>
requires detail::comparable_to_error_code<T>
bool error_utils::Error::is |
( |
T && | code | ) |
const |
|
inlinenodiscardconstexprnoexcept |
Check if the error is of a specific type.
- Parameters
-
code | The error code to check against |
- Template Parameters
-
T | The type of the error code |
- Returns
- True if the error matches the specified code.
◆ is_any_of()
template<typename Code, typename... Others>
requires detail::comparable_to_error_code<Code> && (detail::comparable_to_error_code<Others> && ...)
bool error_utils::Error::is_any_of |
( |
Code && | code, |
|
|
Others &&... | others ) const |
|
inlinenodiscardconstexprnoexcept |
Check if the error belongs to any of the specified error codes or error conditions.
- Parameters
-
code | The first error code/condition to check against |
others | Other error codes/conditions to check against |
- Template Parameters
-
Code | The type of the first argument |
Others | The types of the other arguments |
- Returns
- True if the error matches any of the arguments.
◆ message()
std::string error_utils::Error::message |
( |
| ) |
const |
|
inlinenodiscardconstexpr |
Get the error message including context if available.
- Returns
- Formatted error message
◆ operator bool()
error_utils::Error::operator bool |
( |
| ) |
const |
|
inlineexplicitnodiscardconstexprnoexcept |
Implicit conversion to bool, indicating whether an error exists.
◆ operator=() [1/2]
Error & error_utils::Error::operator= |
( |
const Error & | other | ) |
|
|
inlineconstexpr |
◆ operator=() [2/2]
Error & error_utils::Error::operator= |
( |
Error && | other | ) |
|
|
inlineconstexprnoexcept |
◆ value()
int error_utils::Error::value |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns the value of the error code.
◆ operator<<
friend std::ostream & operator<< |
( |
std::ostream & | os, |
|
|
const Error & | obj ) |
|
friend |
◆ operator<=> [1/2]
friend auto operator<=> |
( |
const Error & | lhs, |
|
|
const Error & | rhs ) |
|
friend |
◆ operator<=> [2/2]
friend auto operator<=> |
( |
const Error & | lhs, |
|
|
const std::error_code & | rhs ) |
|
friend |
◆ operator== [1/3]
friend bool operator== |
( |
const Error & | lhs, |
|
|
const Error & | rhs ) |
|
friend |
◆ operator== [2/3]
friend bool operator== |
( |
const Error & | lhs, |
|
|
const std::error_code & | rhs ) |
|
friend |
◆ operator== [3/3]
friend bool operator== |
( |
const Error & | lhs, |
|
|
const std::error_condition & | rhs ) |
|
friend |
◆ swap
Swap the contents of two Error objects.
The documentation for this class was generated from the following file: