1 // Copyright 2018 The Abseil Authors.
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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.
15 // -----------------------------------------------------------------------------
17 // -----------------------------------------------------------------------------
19 // This header file defines the `absl::bad_any_cast` type.
21 #ifndef ABSL_TYPES_BAD_ANY_CAST_H_
22 #define ABSL_TYPES_BAD_ANY_CAST_H_
26 #include "absl/base/config.h"
28 #ifdef ABSL_HAVE_STD_ANY
33 using std::bad_any_cast;
36 #else // ABSL_HAVE_STD_ANY
40 // -----------------------------------------------------------------------------
42 // -----------------------------------------------------------------------------
44 // An `absl::bad_any_cast` type is an exception type that is thrown when
45 // failing to successfully cast the return value of an `absl::any` object.
49 // auto a = absl::any(65);
50 // absl::any_cast<int>(a); // 65
52 // absl::any_cast<char>(a);
53 // } catch(const absl::bad_any_cast& e) {
54 // std::cout << "Bad any cast: " << e.what() << '\n';
56 class bad_any_cast : public std::bad_cast {
58 ~bad_any_cast() override;
59 const char* what() const noexcept override;
62 namespace any_internal {
64 [[noreturn]] void ThrowBadAnyCast();
66 } // namespace any_internal
69 #endif // ABSL_HAVE_STD_ANY
71 #endif // ABSL_TYPES_BAD_ANY_CAST_H_