struct vs class for small math types?

Bill Baxter dnewsgroup at billbaxter.com
Tue Oct 24 19:45:08 PDT 2006


Mike Parker wrote:
> Bill Baxter wrote:
>>
>> However, for example, with 4 doubles in a quaternion we're talking 32 
>> bytes for just one of those guys.  Normally in C++ I would write 
>> operator overloads and such using 'const quat&' as the argument type 
>> to avoid copying the data on the stack.  Is there a way to do that in D? 
> 
> Use inout arg types. Doesn't give you const, but gives you reference 
> semantics:
> 
> void func(inout MyStruct ms)
> {
>    ms.x = 10;
>    ms.y = 20;
> }
> 
> void main()
> {
>    MyStruct ms;
>    func(ms);
>    writefln(ms.x, ", ", ms.y);
> }

Ah, right.  That is the equivalent of &, isn't it.  Passing pointers 
doesn't give me const either so I guess it's ok.

Wasn't D going to get const-by-default at some point?  I would like that.

--bb



More information about the Digitalmars-d-learn mailing list