boxing, struct opAssign and constructors
gena
gbatyan at gmail.com
Sat Feb 14 05:25:23 PST 2009
Let's say I have some boxing implementation using structs.
With D1 one could have
struct Value {
Value opAssign(double arg){...}
}
Value v1, v2;
v1 = v2;
With D2 (at least 014 and 023) I get compilation error:
function Value.opAssign (double arg) does not match parameter types (Value)
This sounds like as soon as you have at least one opAssign you MUST
write the 'copy-constructor-like' version of opAssign
BTW, what's the right jargon for such 'reflective' opAssign?
Why not giving an OPTION to let compiler create the fastest
copy-ctor-like opAssign automatically, as it does if I haven't defined
any opAssigns?
-------------------------------
having the above struct definition,
Value v = 10
gives compilation error:
Error: cannot cast int to Value[]
why no line number in error?
Where does [] assumption come from?
whereas
Value v = 10.0
gives
test.d(25): Error: cannot cast double to Value
and finally
Value v; v = 10;
Value v; v = 10.0;
do compile and work the same.
NOTE: there is NO opAssign for int, only for double and Value.
-------------------------------
I couldn't find other way of calling struct constructors except using
new operator, shouldn't there be a way to do the same on stack? Say
struct Value {
this(double arg) {...}
}
Value v(10)
AND/OR maybe the above
Value v = 10
to be interpreted as calling the constructor?
right now only following initializer seems to work:
Value v; v = 10;
But It's ugly and I tend to question the efficiency of the produced code
More information about the Digitalmars-d
mailing list