Const sucks

Derek Parnell derek at nomail.afraid.org
Mon Sep 10 18:02:41 PDT 2007


On Mon, 10 Sep 2007 15:22:23 -0700, Walter Bright wrote:

> Derek Parnell wrote:
>> Remind me again what the difference between 'const' and 'invariant'
>> is.
> 
> 'const' means a I can't change it (but someone else can, such as someone
> in a different thread). 'invariant' means nuttin' can change it, not
> no-how, not no-way.

Thank you. Because the terms in English are synonyms, its a bit hard,
without constant usage, to remember this stuff. Of course, once it is
permanently in D and I'm using it all the time, no doubt it'll stick ...
pity about the newbies though.

>> What do these below mean ...
>> 
>> const int (* p)
> 
> syntax error
> 
>> const int *(p)
> 
> syntax error
> 
>> const int (*) p
> 
> syntax error
> 
> Imagine if const were a template called Const, and we used that template
> to form a new type that was const of the old type. We'd invoke it like:
> 	Const!(T) t;
> Now, just s/Const!/const/, and the syntax should make sense.

Thanks. I thought as much.
 
>>> o  tail const of a struct would have to be done by making the
>>> struct a template:
>>> 
>>> struct S(T) { T member; } S!(int)   // tail mutable S!(const(int))
>>> // tail const
>> 
>> But most structs contain multiple members, and usually of different
>> types.
> 
> That's up to the struct designer.

What does that answer mean?!?!?!

Ok, let's back up a second. You say "struct S(T) { T member; } S!(int)   //
tail mutable S!(const(int)) >>> // tail const" to which I assumed you meant
that you can ONLY have tail const structs if every member of the struct is
of a type mentioned in the template argument.

In other words, if I have a struct with three members, each of a different
type, I need to code ...

struct S3(T, U, V)
{
   T member1;
   U member2;
   V member3;
}

S3!(const(int), const(float), const(bool));

and so on for 4, 5, 6, .... 23 member structs.

I'm sure I'm misunderstanding you, because this is really silly.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
11/09/2007 10:52:30 AM



More information about the Digitalmars-d mailing list