Const template

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Jan 23 07:24:44 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Bruno Medeiros wrote:
>> Andrei Alexandrescu (See Website For Email) wrote:
>>> Today, Walter and myself have come with a semantics for const (as in, 
>>> "read-only view" that) seems to be a good starting point. The details 
>>> are yet to be ironed out, but here's the basic plot:
>>>
>>
>> So the keyword for the "read-only view" will be 'const' too? It will 
>> share space with the 'const' as in "compile time constant" ?
> 
> Yes. This is arguably a weak point of the design.
> 

Indeed. :(  Won't this cause must woe afterwards, so that it should be 
changed?
Also will the compile-time const also be a "storage class" (i.e., part 
of the type)? If so how do we distinguish both? As in, how do we check a 
types "storage classes":
   is(typeof(foo) == const) // ?


> 
>>> * Constructors and destructors can figure the storage class of the 
>>> object being constructed. This is useful for selecting different 
>>> allocation strategies for immutable vs. mutable objects:
>>>
>>> class Widget
>>> {
>>>   this(int i) { ... }
>>>   this(const)(int i) { ... }
>>>   ~this() { ... }
>>>   ~this(const)() { ... }
>>> }
>>>
>>> Const cdtors can obviously mutate the object being cdted. In a cdtor, 
>>> 'const' is not enforced -- it's just an information for the programmer.
>>>
>>
>> Whoa, huh? What's the meaning of a const constructor or of a const 
>> destructor? How would they even be invoked?
> 
> class Widget { ... }
> auto a = new Widget; // invokes this()
> auto b = new const Widget; // invokes this(const)()
> 
> 
> Andrei

Ok, but what is such a const object? Is it an object that actually does 
not change? (as opposed to simply a read-only view of it?)

And what is the difference between a normal delete, and the deletion of 
a const reference? (the latter doesn't even make sense to me, delete is 
a mutating operation)


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



More information about the Digitalmars-d mailing list