89 virtual std::string_view
name() const noexcept = 0;
97 virtual std::
string message(
int code) const = 0;
113 int other_code) const noexcept {
114 return (
this == &other_category) && (code == other_code);
128 return this == &other;
135 return !(*
this == other);
142 return std::less<const error_category*>()(
this, &other);
217 std::string_view
name() const noexcept
override {
226 std::string
message(
int code)
const override {
228 case success:
return "Success";
233 case timeout:
return "Operation timed out";
234 case cancelled:
return "Operation was cancelled";
241 default:
return "Unknown common error (code: " + std::to_string(code) +
")";
306 :
code_(
static_cast<int>(code))
338 explicit operator bool() const noexcept {
return code_ != 0; }
369 return !(*
this == other);
376 if (*
category_ < *other.category_)
return true;
377 if (*other.category_ < *
category_)
return false;
378 return code_ < other.code_;
407template<
typename Category>
419 return ec.value() == 0;
429 return ec.value() != 0;
Error category for common/shared error codes.
std::string message(int code) const override
Returns a human-readable message for the error code.
common_error_category()=default
@ operation_not_supported
std::string_view name() const noexcept override
Returns the category name.
static const common_error_category & instance() noexcept
Returns the singleton instance of common_error_category.
Abstract base class for error code categories.
virtual std::string_view name() const noexcept=0
Returns the unique name of this error category.
virtual bool equivalent(int code, const error_category &other_category, int other_code) const noexcept
Checks if an error code in this category is equivalent to another.
bool operator!=(const error_category &other) const noexcept
Inequality comparison between categories.
error_category & operator=(error_category &&)=delete
bool operator==(const error_category &other) const noexcept
Equality comparison between categories.
virtual std::string message(int code) const =0
Returns a human-readable message for the given error code.
bool operator<(const error_category &other) const noexcept
Less-than comparison for use in ordered containers.
error_category(error_category &&)=delete
error_category & operator=(const error_category &)=delete
error_category()=default
Protected default constructor.
error_category(const error_category &)=delete
virtual ~error_category()=default
Virtual destructor for proper cleanup of derived classes.
A type-safe error code that carries its category.
typed_error_code() noexcept
Default constructor creates a success error code.
const error_category & category() const noexcept
Returns the error category.
int value() const noexcept
Returns the error code value.
std::string_view category_name() const noexcept
Returns the category name.
bool operator<(const typed_error_code &other) const noexcept
Less-than comparison for use in ordered containers.
bool operator==(const typed_error_code &other) const noexcept
Equality comparison.
typed_error_code(common_error_category::codes code) noexcept
Constructs from common_error_category::codes enum.
bool operator!=(const typed_error_code &other) const noexcept
Inequality comparison.
void assign(int code, const error_category &category) noexcept
Assigns a new error code value and category.
const error_category * category_
std::string message() const
Returns a human-readable error message.
typed_error_code(int code, const error_category &category) noexcept
Constructs an error code with the given value and category.
void clear() noexcept
Clears the error code to success state.
typed_error_code make_typed_error_code(common_error_category::codes code) noexcept
Creates a typed_error_code from common_error_category::codes enum.
bool is_success(const typed_error_code &ec) noexcept
Checks if a typed_error_code represents success (no error).
bool is_error(const typed_error_code &ec) noexcept
Checks if a typed_error_code represents an error.