constness for arrays
Chad J
gamerChad at _spamIsBad_gmail.com
Tue Jul 18 21:14:38 PDT 2006
Andrew Fedoniouk wrote:
>
> What is the problem with the following:
>
> typedef(T) array T[]
> {
> void opAdd(array a1, array a2)
> {
>
> }
> }
>
> ?
>
In the usage.
How do you use it?
Something like this?
array!(short) foo = [1,2,3];
array!(short) bar = [4,5,6];
array!(short) result = foo + bar;
// result is now [5,7,9]
not too bad... how about multidimensional stuff...
array!(array!(short)) foo = [[1,2],[3,4]];
array!(array!(short)) bar = [[5,6],[7,8]];
// um, maybe a matrix multiply or something. I don't feel like it.
Well doable, but it would be better to have ordinary array syntax.
Also, what if some external library passes in an ordinary array that is
not set up as one of these types, and you want to use the new fancy
features on it:
void gimmeAnArray( short[] foo )
{
array!(short) bar = array!(short).convert( foo );
// ugh
array!(short) bar = array.convert( foo );
// ahh IFTI is better, but this whole line should be unnecessary IMO.
...
}
I suppose the problem I have with your syntax suggestion is that it's
impossible to add properties to existing types. It forces you to define
new types to add properties.
More information about the Digitalmars-d
mailing list