My Kingdom For ...

Robert Fraser fraserofthenight at gmail.com
Thu Feb 21 06:04:20 PST 2008


Jarrett Billingsley wrote:
> "Robert Fraser" <fraserofthenight at gmail.com> wrote in message 
> news:fpjuh5$uai$1 at digitalmars.com...
>> Darryl Bleau wrote:
>>> opIndexConcat
>>> opIndexConcatAssign
> 
> // Contrived, but shows the issue.
> struct IntArray
> {
>     int[] mData;
> 
>     int opIndex(size_t idx)
>     {
>         return mData[idx];
>     }
> }
> 
> int[] realArray = [1, 2, 3];
> realArray[0]++; // now contains [2, 2, 3]
> 
> IntArray a;
> a.mData = [1, 2, 3];
> a[0]++; // FAIL
> 
> In other words without these opIndexSomethingAssign overloads or ref returns 
> it's impossible to make a user container type behave just like a built-in 
> one.
> 
> (as an aside MiniD solves this by defining "a[0]++" to be "temp = a[0]; 
> temp++; a[0] = temp;" but that's beside the point.) 

Ah, I see! Ref returns are a more general & overall happier solution, IMO.



More information about the Digitalmars-d mailing list