BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_badvariantaccess.h
Go to the documentation of this file.
1/// @file bslstl_badvariantaccess.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_badvariantaccess.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_BADVARIANTACCESS
9#define INCLUDED_BSLSTL_BADVARIANTACCESS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_badvariantaccess bslstl_badvariantaccess
15/// @brief Provide an exception class thrown by `bsl::variant`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_badvariantaccess
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_badvariantaccess-purpose"> Purpose</a>
25/// * <a href="#bslstl_badvariantaccess-classes"> Classes </a>
26/// * <a href="#bslstl_badvariantaccess-description"> Description </a>
27///
28/// # Purpose {#bslstl_badvariantaccess-purpose}
29/// Provide an exception class thrown by `bsl::variant`.
30///
31/// # Classes {#bslstl_badvariantaccess-classes}
32///
33/// - bsl::bad_variant_access: exception type thrown by `bsl::variant`
34///
35/// @see bslstl_variant, bslstl_stdexceptionutil
36///
37/// # Description {#bslstl_badvariantaccess-description}
38/// This component provides the `bsl::bad_variant_access` exception
39/// class. This exception is thrown by `bsl::get` when a `bsl::variant` does
40/// not contain the requested alternative and `bsl::visit` when a `bsl::variant`
41/// does not contain a value. If `std::variant` is available,
42/// `bsl::bad_variant_access` is an alias to `std::bad_variant_access`.
43/// @}
44/** @} */
45/** @} */
46
47/** @addtogroup bsl
48 * @{
49 */
50/** @addtogroup bslstl
51 * @{
52 */
53/** @addtogroup bslstl_badvariantaccess
54 * @{
55 */
56
57#include <bslscm_version.h>
58
59#include <bsls_exceptionutil.h>
60#include <bsls_keyword.h>
62
63#include <exception>
64
65#ifdef BDE_BUILD_TARGET_EXC
66
67#if defined(BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY) && \
68 !(defined(BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED) && \
69 (BSLS_LIBRARYFEATURES_FORCE_ABI_ENABLED < 17))
70 #define BSLSTL_BAD_VARIANT_ACCESS_IS_ALIASED 1
71#endif // Has C++17 and not disabled
72
73
74#ifdef BSLSTL_BAD_VARIANT_ACCESS_IS_ALIASED
75 #include <variant> // for 'std::bad_variant_access'
76#endif // BSLSTL_BAD_VARIANT_ACCESS_IS_ALIASED
77
78namespace bsl {
79#ifdef BSLSTL_BAD_VARIANT_ACCESS_IS_ALIASED
80using std::bad_variant_access;
81#else
82 // ========================
83 // class bad_variant_access
84 // ========================
85
86class bad_variant_access : public std::exception {
87 public:
88 // CREATORS
89
90 /// Create a @ref bad_variant_access object.
91 /// \note Note that this function is
92 /// explicitly user-declared, to make it simple to declare `const`
93 /// objects of this type.
94 bad_variant_access() BSLS_KEYWORD_NOEXCEPT;
95
96 // ACCESSORS
97
98 /// Return a pointer to the string literal "bad_variant_access", with a storage duration of the lifetime of the program.
99 ///
100 /// \note Note that the
101 /// caller should *not* attempt to free this memory.
102 /// \note Note that the
103 /// @ref bsls_exceptionutil macro `BSLS_NOTHROW_SPEC` is deliberately not
104 /// used here, as a number of standard libraries declare `what` in the
105 /// base `exception` class explicitly with the no-throw specification,
106 /// even in a build that may not recognize exceptions.
107 const char *what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
109};
110
111// ============================================================================
112// INLINE DEFINITIONS
113// ============================================================================
114
115 // ------------------------
116 // class bad_variant_access
117 // ------------------------
118
119inline
120bad_variant_access::bad_variant_access() BSLS_KEYWORD_NOEXCEPT
121: std::exception()
122{
123}
124
125inline
126const char *bad_variant_access::what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
127{
128 return "bad_variant_access";
129}
130#endif // BSLSTL_BAD_VARIANT_ACCESS_IS_ALIASED
131
132} // close namespace bsl
133
134#endif // BDE_BUILD_TARGET_EXC
135#endif
136
137// ----------------------------------------------------------------------------
138// Copyright 2023 Bloomberg Finance L.P.
139//
140// Licensed under the Apache License, Version 2.0 (the "License");
141// you may not use this file except in compliance with the License.
142// You may obtain a copy of the License at
143//
144// http://www.apache.org/licenses/LICENSE-2.0
145//
146// Unless required by applicable law or agreed to in writing, software
147// distributed under the License is distributed on an "AS IS" BASIS,
148// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
149// See the License for the specific language governing permissions and
150// limitations under the License.
151// ----------------------------- END-OF-FILE ----------------------------------
152
153/** @} */
154/** @} */
155/** @} */
#define BSLS_EXCEPTION_VIRTUAL_NOTHROW
Definition bsls_exceptionutil.h:402
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition bdlat_valuetypefunctions.h:939
Definition bdldfp_decimal.h:5549