Referring to array element by descriptive name

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 14 10:20:04 PST 2017


On Saturday, 14 January 2017 at 15:11:40 UTC, albert-j wrote:
> Is it possible to refer to an array element by a descriptive 
> name, just for code clarity, without performance overhead? E.g.
>
> void aFunction(double[] arr) {
>     double importantElement = arr[3];
>     ... use importantElement ...
> }
>
> But the above, I suppose, introduces an extra copy operation?

  Is the array always a fixed size? Or what?

  I wonder since you might get away with a union, or a struct that 
simply redirects the information appropriately. However it's a 
lot of writing for very little benefit at all.

  But honestly for as little loss you'll get of copying the one 
element and then copying it back (maybe if you change it) I doubt 
it will mean much if you just ignore trying to do a 0-cost 
aliasing as you are trying to do. You'd have to be doing it 
millions of times for such a copy to be noticeable.


More information about the Digitalmars-d-learn mailing list