[#absl-down_cast-04a] = xref:absl.adoc[absl]::down_cast :relfileprefix: ../ :mrdocs: `down_cast` overloads == Synopses Declared in `<absl/base/casts.h>` 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.) [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename To, typename From> [[nodiscard]] To xref:absl/down_cast-048.adoc[down_cast](From& f); ---- [.small]#xref:absl/down_cast-048.adoc[_» more..._]# An "upcast", i.e. a conversion from a pointer to an object to a pointer to a base subobject, always succeeds if the base is unambiguous and accessible, and so it's fine to use implicit_cast. [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< typename To, typename From> [[nodiscard]] To xref:absl/down_cast-06.adoc[down_cast](From* f); ---- [.small]#xref:absl/down_cast-06.adoc[_» more..._]# == Return Value * `f`, downcast to `To`. * `f`, downcast to `To`, or null if `f` is null. [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]#