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);
}