Function templates do implicit conversions for their arguments

TommiT tommitissari at hotmail.com
Thu Jul 4 10:05:37 PDT 2013


On Thursday, 4 July 2013 at 15:59:21 UTC, TommiT wrote:
> 
> struct Toy
> {
>     alias Wrapped = Wrap!Toy;
>
>     @implicit Wrapped opCast(T : Wrapped)()
>     {
>         return Wrapped.init;
>     }
> }

Let me clarify that arguably silly looking syntax. The @implicit 
opCast operator simply means that any instance of Toy is 
implicitly convertible to an instance of Wrapped!Toy, exactly 
like any instance of type int[10] is implicitly convertible to an 
instance of type int[].


More information about the Digitalmars-d mailing list