D - [BUG?] Proxy object and delete
- J Anderson (35/35) Feb 12 2004 template ListT(T)
- Matthew (10/43) Feb 12 2004 I can't comment on the bug/feature issue, but I think this idiom is bad.
- Manfred Nowak (13/13) Feb 12 2004 J Anderson wrote:
- J Anderson (5/19) Feb 12 2004 Why use a proxy object at all? Nar, I know the above works but then you...
template ListT(T) { class Proxy { this(List thelist, int i) { list = thelist; index = i;} ~this() { list.remove(index); } private: List list; int index; } class List { void remove(int i) { printf("remove %d\n", i); //... } Proxy opIndex(int i) { Proxy proxy = new Proxy(this, i); return proxy; } } } int main ( char [] [] args ) { ListT!(int).List test = new ListT!(int).List(); delete test[1]; //Doesn't work (C:\Program Files\DIDE\Projects\test66\test66.d(52): 'test.opIndex(1)' is not an lvalue) return 1; } -- -Anderson: http://badmama.com.au/~anderson/
Feb 12 2004
I can't comment on the bug/feature issue, but I think this idiom is bad. This is an attempt to be consistent with the use of delete for removal of keys from associative arrays. Rather than try and be conformant with this syntax, why not fix it? In other words, the use of delete with associative arrays is inconsistent and plain wrong. Let's have another way of doing it "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c0hbba$2sk3$2 digitaldaemon.com...template ListT(T) { class Proxy { this(List thelist, int i) { list = thelist; index = i;} ~this() { list.remove(index); } private: List list; int index; } class List { void remove(int i) { printf("remove %d\n", i); //... } Proxy opIndex(int i) { Proxy proxy = new Proxy(this, i); return proxy; } } } int main ( char [] [] args ) { ListT!(int).List test = new ListT!(int).List(); delete test[1]; //Doesn't work (C:\Program Files\DIDE\Projects\test66\test66.d(52): 'test.opIndex(1)' is not anlvalue)return 1; } -- -Anderson: http://badmama.com.au/~anderson/
Feb 12 2004
J Anderson wrote: | delete test[1]; //Doesn't work Do you mean: int main ( char [] [] args ) { ListT!(int).List test = new ListT!(int).List(); ListT!(int).Proxy p; p= test[1]; delete p; return 1; } So long.
Feb 12 2004
Manfred Nowak wrote:J Anderson wrote: | delete test[1]; //Doesn't work Do you mean: int main ( char [] [] args ) { ListT!(int).List test = new ListT!(int).List(); ListT!(int).Proxy p; p= test[1]; delete p; return 1; } So long.Why use a proxy object at all? Nar, I know the above works but then you might as well write a method. -- -Anderson: http://badmama.com.au/~anderson/
Feb 12 2004