The following code does not compile. Note that the exact same functions are present in both the inner and outer structs, and that opIndex works for both.
struct Foo{
struct Bar {
int opIndex( size_t index ) {
return 3;
}
void opIndexAssign( int value, size_t index ) {
}
}
@property
auto bar( ) {
return Bar( );
}
int opIndex( size_t index ) {
return 3;
}
void opIndexAssign( int value, size_t index ) {
}
}
void main( ) {
Foo f;
f[3] = f[2];
Foo.Bar b;
b[3] = b[2];
f.bar[3] = f.bar[2]; // Fails
}
foo.d(28): Error: f.bar()[3u] is not an lvalue
Comment #1 by alvaro.segura — 2012-03-05T13:56:35Z
Note that this works instead:
f.bar()[3]= f.bar[2];
if @property is not enforced. It's the same temporary struct returned, but without properties.
Fixing this would allow implementing "indexed properties" as long as D does not provide them natively. i.e, things like:
image.pixels[x,y] = Rgb(0,0,0);
treeViewItem.text[2] = "text for column 2 in this item";
Comment #2 by nilsbossung — 2012-03-06T23:34:22Z
*** Issue 5202 has been marked as a duplicate of this issue. ***