BDE 4.14.0 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#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
68#include <variant> // for 'std::bad_variant_access'
69#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
70
71namespace bsl {
72#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
73using std::bad_variant_access;
74#else
75 // ========================
76 // class bad_variant_access
77 // ========================
78
79class bad_variant_access : public std::exception {
80 public:
81 // CREATORS
82
83 /// Create a `bad_variant_access` object. Note that this function is
84 /// explicitly user-declared, to make it simple to declare `const`
85 /// objects of this type.
86 bad_variant_access() BSLS_KEYWORD_NOEXCEPT;
87
88 // ACCESSORS
89
90 /// Return a pointer to the string literal "bad_variant_access", with a
91 /// storage duration of the lifetime of the program. Note that the
92 /// caller should *not* attempt to free this memory. Note that the
93 /// @ref bsls_exceptionutil macro `BSLS_NOTHROW_SPEC` is deliberately not
94 /// used here, as a number of standard libraries declare `what` in the
95 /// base `exception` class explicitly with the no-throw specification,
96 /// even in a build that may not recognize exceptions.
97 const char *what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
99};
100
101// ============================================================================
102// INLINE DEFINITIONS
103// ============================================================================
104
105 // ------------------------
106 // class bad_variant_access
107 // ------------------------
108
109inline
110bad_variant_access::bad_variant_access() BSLS_KEYWORD_NOEXCEPT
111: std::exception()
112{
113}
114
115inline
116const char *bad_variant_access::what() const BSLS_EXCEPTION_VIRTUAL_NOTHROW
117{
118 return "bad_variant_access";
119}
120#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
121
122} // close namespace bsl
123
124#endif // BDE_BUILD_TARGET_EXC
125#endif
126
127// ----------------------------------------------------------------------------
128// Copyright 2023 Bloomberg Finance L.P.
129//
130// Licensed under the Apache License, Version 2.0 (the "License");
131// you may not use this file except in compliance with the License.
132// You may obtain a copy of the License at
133//
134// http://www.apache.org/licenses/LICENSE-2.0
135//
136// Unless required by applicable law or agreed to in writing, software
137// distributed under the License is distributed on an "AS IS" BASIS,
138// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139// See the License for the specific language governing permissions and
140// limitations under the License.
141// ----------------------------- END-OF-FILE ----------------------------------
142
143/** @} */
144/** @} */
145/** @} */
#define BSLS_EXCEPTION_VIRTUAL_NOTHROW
Definition bsls_exceptionutil.h:402
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition bdlb_printmethods.h:283
Definition bdldfp_decimal.h:5188