Unofficial wish list status.

Chris Nicholson-Sauls ibisbasenji at gmail.com
Mon Jan 1 13:27:22 PST 2007



Xinok wrote:
> -- Renew
> I don't understand why you can't simply use a low-level operation like memcpy? The
> only difference is the memory address will change. The biggest issue is that it
> might break pointers, but this is still an issue whether you use renew or not:
> 
> int* ptr = new int[5];
> int* b = &ptr[3];
> int* tmp = new int[10];
> for(int i = 0; i < 5; i++) tmp[i] = ptr[i];
> delete ptr; ptr = tmp;
> // Oops! pointer 'b' is now broken
> 
> If it's really that important, then perhaps defining a 'renew' operator is the way
> to go, something which is more efficient than a copy constructor.
> class PP{
>     opRenew(void* old){ } // The argument could be the memory address in which the
> object used to be located
> }
> 
> -- Associative Array Initalization
> I think my design makes very much sense. You're telling the compiler which index
> you want to initalize. What better way to do that than to use []?
> int[int] arr = [[0] = 15, [1] = 30, [2] = 45];
> 
> In addition, because I use the assignment operator =, it's logical to do this:
> int[][int] arr = [[0] = [15, 30, 45], [1] = [60, 75]];
> 
> The expression is contained within the square brackets [], so you aren't limited
> to what you can do with the expression:
> int a = 15;
> int[int] arr = [[a = 30] = 45];
> int[int] b = [[a = arr[30] > 0 ? 1 : 2] = 12];
> 
> Using : for structs works because you provide a symbol, not an expression.
> struct SS { int a, b, c; }
> static SS obj = { a : 15, b : 45 }; // 'a' is a symbol
> This is the same reason using : works for specialization.
> 
> 
> -- Multi-Dimensional Allocation
>> How does this differ from
>>
>> int[][][] bar;
>> ...
>> bar = new int[][][](5,20,30);
> 
> The whole purpose is so you could use it with pointers. This doesn't seem to work:
> int** ptr = new int[][](5, 20);

Except that as of last release (and I actually think it was a good idea) arrays are no 
longer implicitly cast'able to pointers, so this still wouldn't work directly.  And the 
canonical means of acquiring a pointer from an array is to use the .ptr property, which is 
always a single indirection pointer even for multidimensional arrays.  (This, presumably, 
would change if we later acquire matrices such as 'int[5, 20]'.)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list