constness for arrays

Andrew Fedoniouk news at terrainformatica.com
Tue Jul 18 21:32:54 PDT 2006


> 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.

If you will define it as

alias array short[]
{
    ...
    void someNewOp(self) {    }
}

then 1) you can use this someNewOp with it and 2)

void gimmeAnArray( short[] foo )
{
    array bar = foo; // ok
    ...
}

Extended alias allows to extend base types.
Extended typedef allows to extend and to reduce operations of base types.

Andrew Fedoniouk.
http://terrainformatica.com






More information about the Digitalmars-d mailing list