D - Overloading "delete"
- Sam McCall (8/8) Feb 09 2004 The "delete" operator is used to delete key/value pairs from associative...
- J Anderson (4/13) Feb 09 2004 You could always use a proxy object.
- Sam McCall (12/27) Feb 10 2004 Or just use myList.delete(i). I was just thinking it might be nice for
- Carlos Santander B. (5/16) Feb 10 2004 I don't remember who told you that, but the 'is' operator is the same as...
- Sam McCall (4/6) Feb 10 2004 Oops... I saw someone discussing an is or isa operator (like
- J Anderson (6/34) Feb 10 2004 I think it would be a good idea to be able to be able to handle deletes
- C (4/42) Feb 12 2004 What is a proxy object ?
- J Anderson (53/56) Feb 12 2004 It's an object that is used in the place of another object (kinda like
The "delete" operator is used to delete key/value pairs from associative arrays. Could it be made possible to overload this, so I can have delete myList[i]; in a custom list class? (maybe this should be possible for arrays too, inefficient though). It seems like a special case keyword that could better be used more generally. Sam
Feb 09 2004
Sam McCall wrote:The "delete" operator is used to delete key/value pairs from associative arrays. Could it be made possible to overload this, so I can have delete myList[i]; in a custom list class? (maybe this should be possible for arrays too, inefficient though). It seems like a special case keyword that could better be used more generally. SamYou could always use a proxy object. -- -Anderson: http://badmama.com.au/~anderson/
Feb 09 2004
J Anderson wrote:Sam McCall wrote:Or just use myList.delete(i). I was just thinking it might be nice for consistency. Or maybe not, dmd doesn't think much of my coding. I was quite taken aback when this code: Iterator!(T) it=iterator(); ... if(it is ListIterator!(T)) elicited this error message: collections.d(129): interface ListIterator has no value Still puzzling over that one :) SamThe "delete" operator is used to delete key/value pairs from associative arrays. Could it be made possible to overload this, so I can have delete myList[i]; in a custom list class? (maybe this should be possible for arrays too, inefficient though). It seems like a special case keyword that could better be used more generally. SamYou could always use a proxy object.
Feb 10 2004
In article <c0aac3$esq$1 digitaldaemon.com>, Sam McCall says...Or just use myList.delete(i). I was just thinking it might be nice for consistency. Or maybe not, dmd doesn't think much of my coding. I was quite taken aback when this code: Iterator!(T) it=iterator(); ... if(it is ListIterator!(T)) elicited this error message: collections.d(129): interface ListIterator has no value Still puzzling over that one :) SamI don't remember who told you that, but the 'is' operator is the same as the '==='. If you want to check if 'it' is a ListIterator, do a cast. ----------------------- Carlos Santander Bernal
Feb 10 2004
Carlos Santander B. wrote:I don't remember who told you that, but the 'is' operator is the same as the '==='. If you want to check if 'it' is a ListIterator, do a cast.Oops... I saw someone discussing an is or isa operator (like instanceof), and then i saw "is" in the spec and jumped to conclusions :( Sam
Feb 10 2004
Sam McCall wrote:J Anderson wrote:I think it would be a good idea to be able to be able to handle deletes of blocks of objects. Also, proxy objects are often more work then it's worth. -- -Anderson: http://badmama.com.au/~anderson/Sam McCall wrote:Or just use myList.delete(i). I was just thinking it might be nice for consistency. Or maybe not, dmd doesn't think much of my coding. I was quite taken aback when this code: Iterator!(T) it=iterator(); .... if(it is ListIterator!(T)) elicited this error message: collections.d(129): interface ListIterator has no value Still puzzling over that one :) SamThe "delete" operator is used to delete key/value pairs from associative arrays. Could it be made possible to overload this, so I can have delete myList[i]; in a custom list class? (maybe this should be possible for arrays too, inefficient though). It seems like a special case keyword that could better be used more generally. SamYou could always use a proxy object.
Feb 10 2004
What is a proxy object ? C "J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c0c3f0$9vn$1 digitaldaemon.com...Sam McCall wrote:J Anderson wrote:I think it would be a good idea to be able to be able to handle deletes of blocks of objects. Also, proxy objects are often more work then it's worth. -- -Anderson: http://badmama.com.au/~anderson/Sam McCall wrote:Or just use myList.delete(i). I was just thinking it might be nice for consistency. Or maybe not, dmd doesn't think much of my coding. I was quite taken aback when this code: Iterator!(T) it=iterator(); .... if(it is ListIterator!(T)) elicited this error message: collections.d(129): interface ListIterator has no value Still puzzling over that one :) SamThe "delete" operator is used to delete key/value pairs from associative arrays. Could it be made possible to overload this, so I can have delete myList[i]; in a custom list class? (maybe this should be possible for arrays too, inefficient though). It seems like a special case keyword that could better be used more generally. SamYou could always use a proxy object.
Feb 12 2004
C wrote:What is a proxy object ? CIt's an object that is used in the place of another object (kinda like boxing). It's kinda like a object that sits in between operations. However, I assumpted because it works in C++ it would work in D. However as the below example shows it doesn't work. I don't know if this is a bug or by-design. I'm going to summit it as a bug anyways. Well in the current example (note code below doesn't work): import std.c.stdio; template ListT(T) { class Proxy { this(List thelist, int i) { list = thelist; index = i;} ~this() { list.remove(index); } //T get() { return T; } private: List list; int index; } class List { T [] List; void add(T t) { List ~= t; } 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(); test.add(10); test.add(20); test.add(30); 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