implicit conversion

uri via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 11 23:22:32 PDT 2014


Sorry should add this is on 2.066.0-rc2 and it used to work on 
2.064.

Cheers,
uri

On Tuesday, 12 August 2014 at 06:21:19 UTC, uri wrote:
> Hi,
>
> I'm trying to allow implicit conversions for my own type 
> happening. I have the following:
>
> ----
> import std.math;
> import std.traits;
>
> struct S(T)
> if(isFloatingPoint!T)
> {
>     T val;
>     alias val this;
> }
> void main()
> {
>
>     auto s = S!float();
>     assert(isNaN(s));
>     s = 10.0;
>     assert(!isNaN(s));
> }
> ----
>
> But I get a compile time error:
>
> ----
> Error: template std.math.isNaN cannot deduce function from 
> argument types !()(S!float), candidates are:
>
> std/math.d(4171):        std.math.isNaN(X)(X x) if 
> (isFloatingPoint!X)
> ----
>
> Is there a way I can to do this, maybe opCall/opCast (I tried 
> these but failed)?
>
> Cheers,
> uri



More information about the Digitalmars-d-learn mailing list