www.digitalmars.com         C & C++   DMDScript  

D - [BUG?] Proxy object and delete

reply J Anderson <REMOVEanderson badmama.com.au> writes:
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
next sibling parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
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 an

     return 1;
 }

 -- 
 -Anderson: http://badmama.com.au/~anderson/

Feb 12 2004
prev sibling parent reply Manfred Nowak <svv1999 hotmail.com> writes:
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
parent J Anderson <REMOVEanderson badmama.com.au> writes:
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.
  

might as well write a method. -- -Anderson: http://badmama.com.au/~anderson/
Feb 12 2004