diff options
Diffstat (limited to 'absl/types/any.h')
-rw-r--r-- | absl/types/any.h | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/absl/types/any.h b/absl/types/any.h index 7cae9dd0..16bda79c 100644 --- a/absl/types/any.h +++ b/absl/types/any.h @@ -56,20 +56,20 @@ #include "absl/base/config.h" #include "absl/utility/utility.h" -#ifdef ABSL_HAVE_STD_ANY +#ifdef ABSL_USES_STD_ANY #include <any> // IWYU pragma: export namespace absl { -inline namespace lts_2019_08_08 { +ABSL_NAMESPACE_BEGIN using std::any; using std::any_cast; using std::bad_any_cast; using std::make_any; -} // inline namespace lts_2019_08_08 +ABSL_NAMESPACE_END } // namespace absl -#else // ABSL_HAVE_STD_ANY +#else // ABSL_USES_STD_ANY #include <algorithm> #include <cstddef> @@ -93,7 +93,7 @@ using std::make_any; #endif // !defined(__GNUC__) || defined(__GXX_RTTI) namespace absl { -inline namespace lts_2019_08_08 { +ABSL_NAMESPACE_BEGIN namespace any_internal { @@ -185,7 +185,7 @@ ValueType* any_cast(any* operand) noexcept; // object, when containing a value, must contain a value type; storing a // reference type is neither desired nor supported. // -// An `absl::any` can only store a type that is copy-constructable; move-only +// An `absl::any` can only store a type that is copy-constructible; move-only // types are not allowed within an `any` object. // // Example: @@ -193,7 +193,7 @@ ValueType* any_cast(any* operand) noexcept; // auto a = absl::any(65); // Literal, copyable // auto b = absl::any(std::vector<int>()); // Default-initialized, copyable // std::unique_ptr<Foo> my_foo; -// auto c = absl::any(std::move(my_foo)); // Error, not copy-constructable +// auto c = absl::any(std::move(my_foo)); // Error, not copy-constructible // // Note that `absl::any` makes use of decayed types (`absl::decay_t` in this // context) to remove const-volatile qualifiers (known as "cv qualifiers"), @@ -518,26 +518,30 @@ ValueType any_cast(any&& operand) { // Description at the declaration site (top of file). template <typename T> const T* any_cast(const any* operand) noexcept { - return operand && operand->GetObjTypeId() == any::IdForType<T>() + using U = + typename std::remove_cv<typename std::remove_reference<T>::type>::type; + return operand && operand->GetObjTypeId() == any::IdForType<U>() ? std::addressof( - static_cast<const any::Obj<T>*>(operand->obj_.get())->value) + static_cast<const any::Obj<U>*>(operand->obj_.get())->value) : nullptr; } // Description at the declaration site (top of file). template <typename T> T* any_cast(any* operand) noexcept { - return operand && operand->GetObjTypeId() == any::IdForType<T>() + using U = + typename std::remove_cv<typename std::remove_reference<T>::type>::type; + return operand && operand->GetObjTypeId() == any::IdForType<U>() ? std::addressof( - static_cast<any::Obj<T>*>(operand->obj_.get())->value) + static_cast<any::Obj<U>*>(operand->obj_.get())->value) : nullptr; } -} // inline namespace lts_2019_08_08 +ABSL_NAMESPACE_END } // namespace absl #undef ABSL_ANY_DETAIL_HAS_RTTI -#endif // ABSL_HAVE_STD_ANY +#endif // ABSL_USES_STD_ANY #endif // ABSL_TYPES_ANY_H_ |