BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_iserrorcodeenum.h
Go to the documentation of this file.
1/// @file bslstl_iserrorcodeenum.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_iserrorcodeenum.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ISERRORCODEENUM
9#define INCLUDED_BSLSTL_ISERRORCODEENUM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14// BDE_VERIFY pragma: -TP25 // CLASSES are not defined in C++11
15
16/// @defgroup bslstl_iserrorcodeenum bslstl_iserrorcodeenum
17/// @brief Provide a compliant standard `is_error_code_enum` trait.
18/// @addtogroup bsl
19/// @{
20/// @addtogroup bslstl
21/// @{
22/// @addtogroup bslstl_iserrorcodeenum
23/// @{
24///
25/// <h1> Outline </h1>
26/// * <a href="#bslstl_iserrorcodeenum-purpose"> Purpose</a>
27/// * <a href="#bslstl_iserrorcodeenum-classes"> Classes </a>
28/// * <a href="#bslstl_iserrorcodeenum-macros"> Macros </a>
29/// * <a href="#bslstl_iserrorcodeenum-canonical-header"> Canonical Header </a>
30/// * <a href="#bslstl_iserrorcodeenum-description"> Description </a>
31/// * <a href="#bslstl_iserrorcodeenum-usage"> Usage </a>
32/// * <a href="#bslstl_iserrorcodeenum-example-1-dedicated-error-values"> Example 1: Dedicated Error Values </a>
33///
34/// # Purpose {#bslstl_iserrorcodeenum-purpose}
35/// Provide a compliant standard `is_error_code_enum` trait.
36///
37/// # Classes {#bslstl_iserrorcodeenum-classes}
38///
39/// - bsl::is_error_code_enum: standard compliant version of `is_error_code_enum`
40///
41/// # Macros {#bslstl_iserrorcodeenum-macros}
42///
43/// - BSL_IS_ERROR_CODE_ENUM_NAMESPACE: namespace to specialize the trait
44///
45/// # Canonical Header {#bslstl_iserrorcodeenum-canonical-header}
46/// bsl_system_error.h
47///
48/// # Description {#bslstl_iserrorcodeenum-description}
49/// This component defines a class template,
50/// `bsl::is_error_code_enum`, intended to be specialized for enumeration types
51/// that are designated as error codes for the `<system_error>` facility. In
52/// C++11 mode, the vendor-supplied `<system_error>` implementation is used
53/// instead, and the corresponding names from `std` are imported into `bsl`.
54/// This component also defines a macro, `BSL_IS_ERROR_CODE_ENUM_NAMESPACE`, to
55/// be used as the namespace in which to write specializations of
56/// `is_error_code_enum`.
57///
58/// ## Usage {#bslstl_iserrorcodeenum-usage}
59///
60///
61/// In this section we show intended use of this component.
62///
63/// ### Example 1: Dedicated Error Values {#bslstl_iserrorcodeenum-example-1-dedicated-error-values}
64///
65///
66/// Suppose we have a dedicated system with a set of possible errors, and we
67/// want to be able to throw descriptive exceptions when an error occurs. We
68/// need to work with the `<system_error>` facility to support this, starting by
69/// marking the enumeration type that defines the error literals as eligible to
70/// participate. We can use `bsl::is_error_code_enum` to do this.
71///
72/// First, we define the set of error values for our system.
73/// @code
74/// struct CarError {
75/// // TYPES
76/// enum Enum {
77/// k_CAR_WHEELS_CAME_OFF = 1,
78/// k_CAR_ENGINE_FELL_OUT = 2
79/// };
80/// };
81/// @endcode
82/// Then, we enable the trait marking this as an error code.
83/// @code
84/// namespace BSL_IS_ERROR_CODE_ENUM_NAMESPACE {
85/// template <> struct is_error_code_enum<CarError::Enum>
86/// : bsl::public true_type { };
87/// } // close namespace BSL_IS_ERROR_CODE_ENUM_NAMESPACE
88/// @endcode
89/// Finally, we verify that the trait marks our type as eligible.
90/// @code
91/// assert(is_error_code_enum<CarError::Enum>::value);
92/// @endcode
93/// @}
94/** @} */
95/** @} */
96
97/** @addtogroup bsl
98 * @{
99 */
100/** @addtogroup bslstl
101 * @{
102 */
103/** @addtogroup bslstl_iserrorcodeenum
104 * @{
105 */
106
107#include <bslscm_version.h>
108
110
112#include <bsls_keyword.h>
113#include <bsls_libraryfeatures.h>
114
115#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
116#include <bsls_nativestd.h>
117#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
118
119// BDE_VERIFY pragma: -SLM01 // Do not complain about macro leaking
120
121#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
122
123#include <system_error>
124
125#define BSL_IS_ERROR_CODE_ENUM_NAMESPACE std
126
127namespace bsl {
128using std::is_error_code_enum;
129
130#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
131using std::is_error_code_enum_v;
132#elif defined BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
133template <class TYPE>
134#ifdef BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES
135inline
136#endif
137BSLS_KEYWORD_CONSTEXPR bool is_error_code_enum_v =
139#endif
140} // close namespace bsl
141
142#else
143
144#define BSL_IS_ERROR_CODE_ENUM_NAMESPACE bsl
145
146namespace bsl {
147 // =========================
148 // struct is_error_code_enum
149 // =========================
150
151/// This class template represents a trait defining whether the specified
152/// enumeration type `TYPE` is to be treated as an error code by the
153/// @ref error_code template methods.
154template <class TYPE>
156{
157};
158
159} // close namespace bsl
160
161#endif
162#endif
163
164// ----------------------------------------------------------------------------
165// Copyright 2019 Bloomberg Finance L.P.
166//
167// Licensed under the Apache License, Version 2.0 (the "License");
168// you may not use this file except in compliance with the License.
169// You may obtain a copy of the License at
170//
171// http://www.apache.org/licenses/LICENSE-2.0
172//
173// Unless required by applicable law or agreed to in writing, software
174// distributed under the License is distributed on an "AS IS" BASIS,
175// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
176// See the License for the specific language governing permissions and
177// limitations under the License.
178// ----------------------------- END-OF-FILE ----------------------------------
179
180/** @} */
181/** @} */
182/** @} */
static const t_TYPE value
Definition bslmf_integralconstant.h:267
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
Definition bdlat_valuetypefunctions.h:939
Definition bslmf_integralconstant.h:261
Definition bslstl_iserrorcodeenum.h:156