BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_iserrorcodeenum

Macros

#define BSL_IS_ERROR_CODE_ENUM_NAMESPACE   std
 

Detailed Description

Outline

Purpose

Provide a compliant standard is_error_code_enum trait.

Classes

Macros

Canonical header: bsl_system_error.h

Description

This component defines a class template, bsl::is_error_code_enum, intended to be specialized for enumeration types that are designated as error codes for the <system_error> facility. In C++11 mode, the vendor-supplied <system_error> implementation is used instead, and the corresponding names from std are imported into bsl. This component also defines a macro, BSL_IS_ERROR_CODE_ENUM_NAMESPACE, to be used as the namespace in which to write specializations of is_error_code_enum.

Usage

In this section we show intended use of this component.

Example 1: Dedicated Error Values

Suppose we have a dedicated system with a set of possible errors, and we want to be able to throw descriptive exceptions when an error occurs. We need to work with the <system_error> facility to support this, starting by marking the enumeration type that defines the error literals as eligible to participate. We can use bsl::is_error_code_enum to do this.

First, we define the set of error values for our system.

struct CarError {
// TYPES
enum Enum {
k_CAR_WHEELS_CAME_OFF = 1,
k_CAR_ENGINE_FELL_OUT = 2
};
};

Then, we enable the trait marking this as an error code.

template <> struct is_error_code_enum<CarError::Enum>
: bsl::public true_type { };
} // close namespace BSL_IS_ERROR_CODE_ENUM_NAMESPACE
#define BSL_IS_ERROR_CODE_ENUM_NAMESPACE
Definition bslstl_iserrorcodeenum.h:123

Finally, we verify that the trait marks our type as eligible.

assert(is_error_code_enum<CarError::Enum>::value);

Macro Definition Documentation

◆ BSL_IS_ERROR_CODE_ENUM_NAMESPACE

#define BSL_IS_ERROR_CODE_ENUM_NAMESPACE   std