Has someone encountered similar issues with -cov?

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 2 06:23:49 PDT 2016


On Saturday, 2 July 2016 at 12:26:34 UTC, Andrei Alexandrescu 
wrote:
>
> How would you reshape this?

Maybe:

U opCast(U, T)(T payload)
{
     import std.traits;

     enum descriptiveName = !isUnsigned!T && isUnsigned!U && 
T.sizeof <= U.sizeof;
     enum unsT_sigU = isUnsigned!T && !isUnsigned!U;
     static if (unsT_sigU)
     {
         static assert(U.sizeof <= T.sizeof);
     }

     if (!descriptiveName || payload >= 0)
     {
         auto result = cast(U) payload;
         if (result == payload)
         {
             if (!unsT_sigU || result >= 0)
             {
                 return result;
             }
         }
     }

     return hook!U(payload);
}




More information about the Digitalmars-d mailing list