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