constness for arrays

Andrew Fedoniouk news at terrainformatica.com
Tue Jul 18 20:23:51 PDT 2006


>> typedef  string char[]
>> {
>>     disable opAssign;
>>     ....
>>     char[] tolower() { ..... }
>> }
>>

> I like that typedef.  Should be templatable though...
>
> typedef(T) array T[]
> {
>     ...
> }

I think so too. It would be nice to have this but I think that
it is enough to be able to define such types in each perticular case.


I think that such extended typedef makes sense for other basic types:

typedef color uint
{
    uint red() {  .... }
    uint blue() {  .... }
    uint green() {  .... }
}

Also such typedef makes sense for classes too.
To avoid vtbl  pollution. Especially actual for templated classes.


>
> Or some such.  In an earlier post ("Module level operator overloading" at 
> http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39504) I was 
> hoping for external functions as operator overloads and IFTI to help with 
> things like array operations.  I just didn't know about external functions 
> at the time.  But if this is supposed to replace external functions, how 
> would I do the array op overloads that external functions would help me 
> with?  Would be unfortunate to write something like this...
>
> typedef(T) T[] T[] // mmm what would this do
> {
>   void opAdd(T[] array1, T[] array2)
>   {
>     etc...
>   }
> }

What is the problem with the following:

typedef(T) array T[]
{
   void opAdd(array a1, array a2)
   {

   }
}

?

Andrew Fedoniouk.
http://terrainformatica.com







More information about the Digitalmars-d mailing list