BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslstl_iserrorconditionenum.h
Go to the documentation of this file.
1/// @file bslstl_iserrorconditionenum.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_iserrorconditionenum.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_ISERRORCONDITIONENUM
9#define INCLUDED_BSLSTL_ISERRORCONDITIONENUM
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_iserrorconditionenum bslstl_iserrorconditionenum
17/// @brief Provide a compliant standard `is_error_condition_enum` trait.
18/// @addtogroup bsl
19/// @{
20/// @addtogroup bslstl
21/// @{
22/// @addtogroup bslstl_iserrorconditionenum
23/// @{
24///
25/// <h1> Outline </h1>
26/// * <a href="#bslstl_iserrorconditionenum-purpose"> Purpose</a>
27/// * <a href="#bslstl_iserrorconditionenum-classes"> Classes </a>
28/// * <a href="#bslstl_iserrorconditionenum-macros"> Macros </a>
29/// * <a href="#bslstl_iserrorconditionenum-description"> Description </a>
30/// * <a href="#bslstl_iserrorconditionenum-usage"> Usage </a>
31/// * <a href="#bslstl_iserrorconditionenum-example-1-dedicated-error-values"> Example 1: Dedicated Error Values </a>
32///
33/// # Purpose {#bslstl_iserrorconditionenum-purpose}
34/// Provide a compliant standard `is_error_condition_enum` trait.
35///
36/// # Classes {#bslstl_iserrorconditionenum-classes}
37///
38/// - bsl::is_error_condition_enum: standard complaint `is_error_condition_enum`
39///
40/// # Macros {#bslstl_iserrorconditionenum-macros}
41///
42/// - BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE: namespace to specialize the triat
43///
44/// **Canonical header:** bsl_system_error.h
45///
46/// # Description {#bslstl_iserrorconditionenum-description}
47/// This component defines a class template,
48/// `bsl::is_error_condition_enum`, intended to be specialized for enumeration
49/// types that are designated as error conditions for the `<system_error>`
50/// facility. In C++11 mode, the vendor-supplied `<system_error>`
51/// implementation is used instead, and the corresponding names from `std` are
52/// imported into `bsl`. This component also defines a macro,
53/// `BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE`, to be used as the namespace in
54/// which to write specializations of `is_error_condition_enum`.
55///
56/// ## Usage {#bslstl_iserrorconditionenum-usage}
57///
58///
59/// In this section we show intended use of this component.
60///
61/// ### Example 1: Dedicated Error Values {#bslstl_iserrorconditionenum-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_condition` 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 condition.
81/// @code
82/// namespace BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE {
83/// template <> struct is_error_condition_enum<CarError::Enum>
84/// : public true_type { };
85/// } // close namespace BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE
86/// @endcode
87/// Finally, we verify that the trait marks our type as eligible.
88/// @code
89/// assert(is_error_condition_enum<CarError::Enum>::value);
90/// @endcode
91/// @}
92/** @} */
93/** @} */
94
95/** @addtogroup bsl
96 * @{
97 */
98/** @addtogroup bslstl
99 * @{
100 */
101/** @addtogroup bslstl_iserrorconditionenum
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_CONDITION_ENUM_NAMESPACE std
124
125namespace bsl {
126using std::is_error_condition_enum;
127
128#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
129using std::is_error_condition_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_condition_enum_v =
136 is_error_condition_enum<TYPE>::value;
137#endif
138} // close namespace bsl
139
140#else
141
142#define BSL_IS_ERROR_CONDITION_ENUM_NAMESPACE bsl
143
144namespace bsl {
145 // ==============================
146 // struct is_error_condition_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 condition by the
151/// @ref error_condition template methods.
152template <class TYPE>
153struct is_error_condition_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