Unofficial wish list status.

Xinok xnknet at gmail.com
Mon Jan 1 11:31:52 PST 2007


-- 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);



More information about the Digitalmars-d mailing list