Change representation of dynamic arrays?

BCS ao at pathlink.com
Sat Oct 20 14:38:49 PDT 2007


Reply to Janice,

> On 10/20/07, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> 
>> It becomes relevant if $ becomes a synonym for .length as was
>> previously
>> proposed.  In that case you don't get to decide how $ is implemented.
>> It has to compute the length, even if that's O(N) and not really
>> needed
>> for computing the $-1'th node.
>> Or if all you're trying to do is make a light wrapper around a
>> built-in array (to, say, add an extra data member to it), then it
>> means that your opIndex could be significantly less efficient than
>> the built-in one.
>> 
> I guess what I was thinking is... suppose I have an arbitrary,
> user-defined collection class:
> 
> MyCollection!(int) c;
> 
> and I want to dereference the last element. The source code might be:
> 
> int n = c[$-1];
> 
> Now, currently, (or if $ gets defined as length), that would get
> turned into:
> 
> int n = c.opIndex(c.length()-1);
> 

if the return of .length is left unrestricted, then you can play games with 
having it return a proxy type that another opIndex then uses.





More information about the Digitalmars-d mailing list