Overload of down_cast for references. Use like this: absl::down_cast<T&>(foo). The code is slightly convoluted because we're still using the pointer form of dynamic cast. (The reference form throws an exception if it fails.)
Declared in <absl/base/casts.h>
template<
typename To,
typename From>
[[nodiscard]]
To
down_cast(From& f);
There's no need for a special const overload either for the pointer or the reference form. If you call down_cast with a const T&, the compiler will just bind From to const T.
| Name | Description |
|---|---|
| f | The source reference to downcast. |