19 Diagnostics library [diagnostics]

19.5 System error support [syserr]

19.5.4 Class error_­condition [syserr.errcondition]

19.5.4.1 Overview [syserr.errcondition.overview]

The class error_­condition describes an object used to hold values identifying error conditions.
[Note
:
error_­condition values are portable abstractions, while error_­code values are implementation specific.
end note
]
namespace std {
  class error_condition {
  public:
    // [syserr.errcondition.constructors], constructors
    error_condition() noexcept;
    error_condition(int val, const error_category& cat) noexcept;
    template<class ErrorConditionEnum>
      error_condition(ErrorConditionEnum e) noexcept;

    // [syserr.errcondition.modifiers], modifiers
    void assign(int val, const error_category& cat) noexcept;
    template<class ErrorConditionEnum>
      error_condition& operator=(ErrorConditionEnum e) noexcept;
    void clear() noexcept;

    // [syserr.errcondition.observers], observers
    int value() const noexcept;
    const error_category& category() const noexcept;
    string message() const;
    explicit operator bool() const noexcept;

  private:
    int val_;                   // exposition only
    const error_category* cat_; // exposition only
  };
}

19.5.4.2 Constructors [syserr.errcondition.constructors]

error_condition() noexcept;
Ensures: val_­ == 0 and cat_­ == &generic_­category().
error_condition(int val, const error_category& cat) noexcept;
Ensures: val_­ == val and cat_­ == &cat.
template<class ErrorConditionEnum> error_condition(ErrorConditionEnum e) noexcept;
Constraints: is_­error_­condition_­enum_­v<ErrorConditionEnum> is true.
Ensures: *this == make_­error_­condition(e).

19.5.4.3 Modifiers [syserr.errcondition.modifiers]

void assign(int val, const error_category& cat) noexcept;
Ensures: val_­ == val and cat_­ == &cat.
template<class ErrorConditionEnum> error_condition& operator=(ErrorConditionEnum e) noexcept;
Constraints: is_­error_­condition_­enum_­v<ErrorConditionEnum> is true.
Ensures: *this == make_­error_­condition(e).
Returns: *this.
void clear() noexcept;
Ensures: value() == 0 and category() == generic_­category().

19.5.4.4 Observers [syserr.errcondition.observers]

int value() const noexcept;
Returns: val_­.
const error_category& category() const noexcept;
Returns: *cat_­.
string message() const;
Returns: category().message(value()).
explicit operator bool() const noexcept;
Returns: value() != 0.

19.5.4.5 Non-member functions [syserr.errcondition.nonmembers]

error_condition make_error_condition(errc e) noexcept;
Returns: error_­condition(static_­cast<int>(e), generic_­category()).