about summary refs log tree commit diff
path: root/absl/types/any.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/types/any.h')
-rw-r--r--absl/types/any.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/absl/types/any.h b/absl/types/any.h
index f3a32812662f..d2e2533f05bc 100644
--- a/absl/types/any.h
+++ b/absl/types/any.h
@@ -515,18 +515,22 @@ 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;
 }