abseil-cpp/absl/types/bad_any_cast.h
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // bad_any_cast.h
17 // -----------------------------------------------------------------------------
18 //
19 // This header file defines the `absl::bad_any_cast` type.
20 
21 #ifndef ABSL_TYPES_BAD_ANY_CAST_H_
22 #define ABSL_TYPES_BAD_ANY_CAST_H_
23 
24 #include <typeinfo>
25 
26 #include "absl/base/config.h"
27 
28 #ifdef ABSL_USES_STD_ANY
29 
30 #include <any>
31 
32 namespace absl {
34 using std::bad_any_cast;
36 } // namespace absl
37 
38 #else // ABSL_USES_STD_ANY
39 
40 namespace absl {
42 
43 // -----------------------------------------------------------------------------
44 // bad_any_cast
45 // -----------------------------------------------------------------------------
46 //
47 // An `absl::bad_any_cast` type is an exception type that is thrown when
48 // failing to successfully cast the return value of an `absl::any` object.
49 //
50 // Example:
51 //
52 // auto a = absl::any(65);
53 // absl::any_cast<int>(a); // 65
54 // try {
55 // absl::any_cast<char>(a);
56 // } catch(const absl::bad_any_cast& e) {
57 // std::cout << "Bad any cast: " << e.what() << '\n';
58 // }
59 class bad_any_cast : public std::bad_cast {
60  public:
61  ~bad_any_cast() override;
62  const char* what() const noexcept override;
63 };
64 
65 namespace any_internal {
66 
67 [[noreturn]] void ThrowBadAnyCast();
68 
69 } // namespace any_internal
71 } // namespace absl
72 
73 #endif // ABSL_USES_STD_ANY
74 
75 #endif // ABSL_TYPES_BAD_ANY_CAST_H_
ABSL_NAMESPACE_END
#define ABSL_NAMESPACE_END
Definition: third_party/abseil-cpp/absl/base/config.h:171
absl::bad_any_cast
Definition: abseil-cpp/absl/types/bad_any_cast.h:59
ABSL_NAMESPACE_BEGIN
#define ABSL_NAMESPACE_BEGIN
Definition: third_party/abseil-cpp/absl/base/config.h:170
absl::bad_any_cast::what
const char * what() const noexcept override
Definition: abseil-cpp/absl/types/bad_any_cast.cc:29
absl::bad_any_cast::~bad_any_cast
~bad_any_cast() override
absl
Definition: abseil-cpp/absl/algorithm/algorithm.h:31
absl::any_internal::ThrowBadAnyCast
void ThrowBadAnyCast()
Definition: abseil-cpp/absl/types/bad_any_cast.cc:33


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:45