Extended Type Design.

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Mar 22 17:46:55 PDT 2007


Tyler Knott wrote:
> Chris Nicholson-Sauls wrote:
>> As I understand, there will be an implicit cast of mutables to 
>> immutables, so assuming 'const' appears under 'invariant' in this 
>> list, I would expect|hope it to be 'const Foo*' so that it is passable 
>> to either 'const' or 'invariant' typed parameters.  Ie:
>>
> 
> Actually, I take back what I said in my previous post in this thread.  
> Taking the address of a final variable should always result in an 
> invariant pointer.  The reason is that invariant references require the 
> data they reference to never, ever change whereas const references 
> expect the data they reference to be changed by other 
> non-const/non-immutable references to that data.  Obviously, since const 
> references can't guarantee the data they reference won't change they 
> can't be cast to immutable references at all, but because const 
> references can still guarantee they won't mutate the data they reference 
> immutable references can be freely cast to const references.

Well, yes, but is 'invariant' transitive like const? I think it is (but 
I'm not sure, I'm getting a bit lost in the thread), and if it is, those 
semantics won't work. I.e., "typeof(&foo) " in my example can't be 
invariant anything.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list