[#absl-down_cast-048] = xref:absl.adoc[absl]::down_cast :relfileprefix: ../ :mrdocs: 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.) == Synopsis Declared in `<absl/base/casts.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename To, typename From> [[nodiscard]] To down_cast(From& f); ---- == Description 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. == Return Value `f`, downcast to `To`. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== == Parameters [cols="1,4"] |=== | Name| Description | *f* | The source reference to downcast. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#