[#absl-down_cast-04a]
= xref:absl.adoc[absl]::down&lowbar;cast
:relfileprefix: ../
:mrdocs:

`down&lowbar;cast` overloads

== Synopses

Declared in `&lt;absl&sol;base&sol;casts&period;h&gt;`

Overload of down&lowbar;cast for references&period; Use like this&colon; absl&colon;&colon;down&lowbar;cast&lt;T&amp;&gt;(foo)&period; The code is slightly convoluted because we&apos;re still using the pointer form of dynamic cast&period; (The reference form throws an exception if it fails&period;)


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    typename To,
    typename From&gt;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
To
xref:absl/down_cast-048.adoc[down&lowbar;cast](From& f);
----

[.small]#xref:absl/down_cast-048.adoc[_» more&period;&period;&period;_]#

An &quot;upcast&quot;, i&period;e&period; 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&apos;s fine to use implicit&lowbar;cast&period;


[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    typename To,
    typename From&gt;
&lsqb;&lsqb;nodiscard&rsqb;&rsqb;
To
xref:absl/down_cast-06.adoc[down&lowbar;cast](From* f);
----

[.small]#xref:absl/down_cast-06.adoc[_» more&period;&period;&period;_]#

== Return Value

* `f`, downcast to `To`&period;
* `f`, downcast to `To`, or null if `f` is null&period;

[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&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
