Does D really need something like const&?

deadalnix deadalnix at gmail.com
Sat Mar 2 01:38:16 PST 2013


On Saturday, 2 March 2013 at 09:31:56 UTC, Namespace wrote:
>> 1/ Generic code. You may not know that the data are big after 
>> starting conglomerating more and more stuff.
> auto ref for templates still exists and won't get away.
>

Passing by ref small struct for nothing is also a performance 
concern. You'll access them via dereference when you could have 
them directly in registers, and reduce the compiler capability of 
doing optimization based on aliasing.

Auto ref is convenient, but look more like an ugly patch than a 
real solution.

>> 2/ Data may be small, but with an expensive copy mecanism.
> Example?
>

struct ValueArray(T) {
     T[] data;
     alias this = data; // Damned, it is broken on 2.062

     this(this) {
         data = data.dup;
     }
}

>> And I can go on and on.
> Yes go on, I'd like to hear more.

I don't see the point of providing more data when you ignored 
half of what I provided and misunderstood the other half.


More information about the Digitalmars-d mailing list