My Kingdom For ...
Jarrett Billingsley
kb3ctd2 at yahoo.com
Thu Feb 21 05:56:30 PST 2008
"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.)
More information about the Digitalmars-d
mailing list