[#absl-implicit_cast-01]
= xref:absl.adoc[absl]::implicit&lowbar;cast
:relfileprefix: ../
:mrdocs:

Performs an implicit conversion between types following the language rules for implicit conversion&semi; if an implicit conversion is otherwise allowed by the language in the given context, this function performs such an implicit conversion&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;typename To&gt;
constexpr
To
implicit&lowbar;cast(To to)
requires !type&lowbar;traits&lowbar;internal&colon;&colon;IsView&lt;std&colon;&colon;enable&lowbar;if&lowbar;t&lt;
        !std&colon;&colon;is&lowbar;reference&lowbar;v&lt;To&gt;, std&colon;&colon;remove&lowbar;cv&lowbar;t&lt;To&gt;&gt;&gt;&colon;&colon;value;
----

== Description

Example&colon;

&sol;&sol; If the context allows implicit conversion&colon; From from&semi; To to &equals; from&semi;

&sol;&sol; Such code can be replaced by&colon; implicit&lowbar;cast&lt;To&gt;(from)&semi;

An `implicit&lowbar;cast()` may also be used to annotate numeric type conversions that, although safe, may produce compiler warnings (such as `long` to `int`)&period; Additionally, an `implicit&lowbar;cast()` is also useful within return statements to indicate a specific implicit conversion is being undertaken&period;

Example&colon;

return implicit&lowbar;cast&lt;double&gt;(size&lowbar;in&lowbar;bytes) &sol; capacity&lowbar;&semi;

Annotating code with `implicit&lowbar;cast()` allows you to explicitly select particular overloads and template instantiations, while providing a safer cast than `reinterpret&lowbar;cast()` or `static&lowbar;cast()`&period;

Additionally, an `implicit&lowbar;cast()` can be used to allow upcasting within a type hierarchy where incorrect use of `static&lowbar;cast()` could accidentally allow downcasting&period;

Finally, an `implicit&lowbar;cast()` can be used to perform implicit conversions from unrelated types that otherwise couldn&apos;t be implicitly cast directly&semi; C&plus;&plus; will normally only implicitly cast &quot;one step&quot; in such conversions&period;

That is, if C is a type which can be implicitly converted to B, with B being a type that can be implicitly converted to A, an `implicit&lowbar;cast()` can be used to convert C to B (which the compiler can then implicitly convert to A using language rules)&period;

Example&colon;

&sol;&sol; Assume an object C is convertible to B, which is implicitly convertible &sol;&sol; to A A a &equals; implicit&lowbar;cast&lt;B&gt;(C)&semi;

Such implicit cast chaining may be useful within template logic&period; This overload participates in overload resolution when `To` is not a view type and not a reference type&period;

== Return Value

The value of `to`, converted to `To`&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *to*
| The value to convert to `To`&period;
|===


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