Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:30

0001 // Copyright 2018 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 // -----------------------------------------------------------------------------
0016 // bad_variant_access.h
0017 // -----------------------------------------------------------------------------
0018 //
0019 // This header file defines the `absl::bad_variant_access` type.
0020 
0021 #ifndef ABSL_TYPES_BAD_VARIANT_ACCESS_H_
0022 #define ABSL_TYPES_BAD_VARIANT_ACCESS_H_
0023 
0024 #include <stdexcept>
0025 
0026 #include "absl/base/config.h"
0027 
0028 #ifdef ABSL_USES_STD_VARIANT
0029 
0030 #include <variant>
0031 
0032 namespace absl {
0033 ABSL_NAMESPACE_BEGIN
0034 using std::bad_variant_access;
0035 ABSL_NAMESPACE_END
0036 }  // namespace absl
0037 
0038 #else  // ABSL_USES_STD_VARIANT
0039 
0040 namespace absl {
0041 ABSL_NAMESPACE_BEGIN
0042 
0043 // -----------------------------------------------------------------------------
0044 // bad_variant_access
0045 // -----------------------------------------------------------------------------
0046 //
0047 // An `absl::bad_variant_access` type is an exception type that is thrown in
0048 // the following cases:
0049 //
0050 //   * Calling `absl::get(absl::variant) with an index or type that does not
0051 //     match the currently selected alternative type
0052 //   * Calling `absl::visit on an `absl::variant` that is in the
0053 //     `variant::valueless_by_exception` state.
0054 //
0055 // Example:
0056 //
0057 //   absl::variant<int, std::string> v;
0058 //   v = 1;
0059 //   try {
0060 //     absl::get<std::string>(v);
0061 //   } catch(const absl::bad_variant_access& e) {
0062 //     std::cout << "Bad variant access: " << e.what() << '\n';
0063 //   }
0064 class bad_variant_access : public std::exception {
0065  public:
0066   bad_variant_access() noexcept = default;
0067   ~bad_variant_access() override;
0068   const char* what() const noexcept override;
0069 };
0070 
0071 namespace variant_internal {
0072 
0073 [[noreturn]] ABSL_DLL void ThrowBadVariantAccess();
0074 [[noreturn]] ABSL_DLL void Rethrow();
0075 
0076 }  // namespace variant_internal
0077 ABSL_NAMESPACE_END
0078 }  // namespace absl
0079 
0080 #endif  // ABSL_USES_STD_VARIANT
0081 
0082 #endif  // ABSL_TYPES_BAD_VARIANT_ACCESS_H_