const

Oskar Linde oskar.lindeREM at OVEgmail.com
Fri Mar 28 07:50:47 PDT 2008


Oskar Linde wrote:
> Janice Caron wrote:
>> On 28/03/2008, Oskar Linde <oskar.lindeREM at ovegmail.com> wrote:
>>>  1. Plain data types don't need the storage constancy to be a part of 
>>> the
>>>  type.
>>
>> But they do, for the following reason. Suppose I implement a custom
>> container. Then I would want
>>
>>     MyContainer!(char)
>>
>> to behave differently from
>>
>>     MyContainer!(const(char))
>>
>> The only way I can see of achieving this is if char and const(char)
>> are distinct types.
> 
> I called const/invariant "type meta qualifiers". They are not part of 
> the type but carry type meta information. It makes sense that you are 
> able to pass the type meta qualifiers to templates that make use of 
> them. There is an analogue with how templates today by default strip the 
> type meta qualifiers.

Some more things to add. Today, say I want to make my own array slice type:

struct Slice(T:T) { T[] slice; }

Now, I can declare such slices:

Slice!(int) a;
Slice!(const int) b;
const Slice!(int) c;
const Slice!(const int) d;

You get some quite different beasts that way due to the transitive 
const. For example, what is the difference between c and d? (Apart from 
them being distinct types)

-- 
Oskar



More information about the Digitalmars-d mailing list