this() not executing code on structs

zoli zoli at freemail.hu
Wed Oct 21 10:11:08 PDT 2009


Andrei Alexandrescu Wrote:

> Today, structs can't write their own this(). There aren't very solid 
> reasons for that except that it makes language implementation more 
> difficult.
> 

If the new "operator" for the class is redesigned to have multiply allocation types 
(allocate on heap, allocate on stack, etc.?), there is no main drawback of using classes instead of structs for small objects( like vec2, vec3) as well.
For function parameters, use the reference for in/out and, use a copy of the original for value parameters ( personally I hate codes where they change the input parameters when they are value types - for larger codes it's hard to track what's going on in the function, and whether it's the original or the modified value...)

I don't think if there's any reason to use struct with member functions from that point, use class instead. And hence struct can be the good old plain data structures again, to give some semantics to a block of memory.

But if the scoped allocation is gone, the struct will require much more construction powers, and will be used more (ex vec2, vec3, etc.)




More information about the Digitalmars-d mailing list