How to define opCast from native types
Cherry
cherry at dream.land
Fri Feb 7 19:50:02 PST 2014
> alias BitV48 = BitVector!48;
> ulong ull;
> BitV48 bits = cast(Bit48) ull.toBitVector;
>
I find it necessary to make the user *cast* explicitly. I just
wanted to add that though I am comfortable with this syntax, it
is not the most efficient way since two methods toBitVector and
opCast are being invoked. That would not be the case if D had
provision for opCastLeft. And the syntax would have been smoother
too.
BTW I still have a ull.toBitVector!N, but aligned with
std.conv:to functionality it makes a runtime check and raises
ConvOverflowException if required.
regards
- Cherry
More information about the Digitalmars-d
mailing list