Casting Structs
Paul D Anderson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 31 14:11:59 PDT 2014
I'm working on the decimal number package for D. A decimal is a
struct with precision, max exponent and rounding mode parameters:
"Decimal!(PRECISION, MAX_EXPO, ROUNDING)". I was trying to
overload the opCast operator for this struct and I found that it
does not seem necessary. I can cast decimals with different
precisions, etc., back and forth without overloading opCast.
This code works:
alias dec9 = Decimal!(9,99);
alias dec10 = Decimal!(10,99);
dec9 bingo = dec9("123.45");
dec10 little = cast(dec10(bingo));
assert(little == dec10("123.45"));
Is this expected behavior?
Paul
More information about the Digitalmars-d-learn
mailing list