constness for arrays

xs0 xs0 at xs0.com
Wed Jul 19 11:38:54 PDT 2006


Andrew Fedoniouk wrote:
>>> typedef  string char[]
>>> {
>>>     disable opAssign;
>>>     ....
>>>     char[] tolower() { ..... }
>>> }

Is there any particular difference from

struct string
{
     char[] data;

     char[] tolower() { .... }
}

?

> I think that such extended typedef makes sense for other basic types:
> 
> typedef color uint
> {
>     uint red() {  .... }
>     uint blue() {  .... }
>     uint green() {  .... }
> }

Is there any particular difference from

struct color {
     uint value;
     uint red() { ... }
     ...
}

?


> Also such typedef makes sense for classes too.

I don't get that.. Since you seem to want a new type, what's wrong with 
deriving?

> To avoid vtbl  pollution. Especially actual for templated classes.

Make the methods or class final, then they don't go into vtbl (or at 
least shouldn't).


xs0



More information about the Digitalmars-d mailing list